-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat process: add process support for unix
- Loading branch information
Showing
3 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include <xdbd_process.h> | ||
#include <stdlib.h> | ||
|
||
static void xdbd_execute_proc(xdbd_t *cycle, void *data); | ||
|
||
xdbd_pid_t xdbd_spawn_process(xdbd_t *xdbd, | ||
xdbd_spawn_proc_pt proc, void *data, char *name) { | ||
xdbd_pid_t pid; | ||
|
||
pid = fork(); | ||
|
||
switch (pid) { | ||
|
||
case -1: | ||
bfdev_log_err("fork() failed while spawning \"%s\"", name); | ||
// xdbd_close_channel(xdbd_processes[s].channel, cycle->log); | ||
return XDBD_INVALID_PID; | ||
|
||
case 0: | ||
proc(xdbd, data); | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
|
||
return pid; | ||
} | ||
|
||
xdbd_pid_t xdbd_execute(xdbd_t *cycle, xdbd_exec_ctx_t *ctx) { | ||
return xdbd_spawn_process(cycle, xdbd_execute_proc, ctx, ctx->name); | ||
} | ||
|
||
|
||
static void xdbd_execute_proc(xdbd_t *cycle, void *data) { | ||
xdbd_exec_ctx_t *ctx = data; | ||
|
||
if (execve(ctx->path, ctx->argv, ctx->envp) == -1) { | ||
bfdev_log_err("execve() failed while executing %s \"%s\"", | ||
ctx->name, ctx->path); | ||
} | ||
|
||
exit(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#ifndef __NGX_PROCESS__H__ | ||
#define __NGX_PROCESS__H__ | ||
#include <xdbd.h> | ||
|
||
typedef pid_t xdbd_pid_t; | ||
|
||
#define XDBD_INVALID_PID -1 | ||
|
||
typedef void (*xdbd_spawn_proc_pt) (xdbd_t *xdbd, void *data); | ||
|
||
typedef struct { | ||
xdbd_pid_t pid; | ||
xdbd_spawn_proc_pt proc; | ||
|
||
} xdbd_process_t; | ||
|
||
typedef struct { | ||
char *path; | ||
char *name; | ||
char *const *argv; | ||
char *const *envp; | ||
} xdbd_exec_ctx_t; | ||
|
||
xdbd_pid_t xdbd_spawn_process(xdbd_t *xdbd, | ||
xdbd_spawn_proc_pt proc, void *data, char *name); | ||
|
||
xdbd_pid_t xdbd_execute(xdbd_t *cycle, xdbd_exec_ctx_t *ctx); | ||
|
||
#define ngx_getpid getpid | ||
#define ngx_getppid getppid | ||
|
||
#endif /*__NGX_PROCESS__H__*/ |