Rev 3304 | Rev 3346 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3304 | Rev 3340 | ||
---|---|---|---|
Line 43... | Line 43... | ||
43 | #include "config.h" |
43 | #include "config.h" |
44 | #include "util.h" |
44 | #include "util.h" |
45 | #include "exec.h" |
45 | #include "exec.h" |
46 | #include "errors.h" |
46 | #include "errors.h" |
47 | 47 | ||
48 | /* TODO: create exec, exev, execve wrappers for task_spawn() */ |
- | |
49 | - | ||
50 | /* Easiest way to handle a shared + allocated string */ |
48 | /* FIXME: Just have find_command() return an allocated string */ |
51 | char *found; |
49 | char *found; |
52 | 50 | ||
53 | /* work-around for access() */ |
51 | /* work-around for access() */ |
54 | unsigned int try_access(const char *f) |
52 | unsigned int try_access(const char *f) |
55 | { |
53 | { |
Line 101... | Line 99... | ||
101 | free(path_tok); |
99 | free(path_tok); |
102 | return (char *) found; |
100 | return (char *) found; |
103 | } |
101 | } |
104 | } |
102 | } |
105 | 103 | ||
106 | /* We didn't find it, just give it back as-is. Could be an alias |
104 | /* We didn't find it, just give it back as-is. */ |
107 | * set in the parent shell */ |
- | |
108 | free(path_tok); |
105 | free(path_tok); |
109 | return (char *) cmd; |
106 | return (char *) cmd; |
110 | } |
107 | } |
111 | 108 | ||
112 | task_id_t try_exec(char *cmd, char **argv) |
109 | unsigned int try_exec(char *cmd, char **argv) |
113 | { |
110 | { |
114 | task_id_t tid; |
111 | task_id_t tid; |
115 | char *tmp; |
112 | char *tmp; |
116 | 113 | ||
117 | tmp = cli_strdup(find_command(cmd)); |
114 | tmp = cli_strdup(find_command(cmd)); |
118 | free(found); |
115 | free(found); |
119 | 116 | ||
120 | /* TODO: put the cwd in front of tmp if tmp[0] != root |
- | |
121 | * which fixes relative paths fed to task_spawn */ |
- | |
122 | - | ||
123 | tid = task_spawn((const char *)tmp, (const char **)argv); |
117 | tid = task_spawn((const char *)tmp, (const char **)argv); |
124 | free(tmp); |
118 | free(tmp); |
125 | 119 | ||
126 | if (tid == 0) |
120 | if (tid == 0) { |
127 | /* HelenOS does not set errno, so all we can do is report |
- | |
128 | * a task ID of 0 as a generic failure. */ |
- | |
129 | cli_error(CL_EEXEC, "Can not spawn %s", cmd); |
121 | cli_error(CL_EEXEC, "Can not spawn %s", cmd); |
- | 122 | return 1; |
|
130 | 123 | } else { |
|
131 | return tid; |
124 | return 0; |
- | 125 | } |
|
132 | } |
126 | } |