Skip to content

Commit

Permalink
[api] Do not create a PID file unless explicitely told to
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalecki committed Jul 2, 2013
1 parent 50d99d3 commit f63a9bb
Showing 1 changed file with 3 additions and 45 deletions.
48 changes: 3 additions & 45 deletions src/aeternum.c
Expand Up @@ -94,7 +94,9 @@ void spawn_child(int detach) {
return;
}

write_pid_file(child_req.pid, pidfile);
if (opts.pidname != NULL) {
write_pid_file(child_req.pid, opts.pidname);
}
}

void spawn_cb(uv_process_t *req, int exit_status, int signal_status) {
Expand Down Expand Up @@ -146,41 +148,6 @@ void configure_stdio() {
}
}

void set_pidfile_path(char *pidname) {
#ifdef _WIN32
WCHAR homedir[MAX_PATH];
if (FAILED(SHGetFolderPathW(NULL, CSIDL_PROFILE, NULL, 0, path)) {
perror("SHGetFolderPathW");
return;
}
#else
const char *homedir = getenv("HOME");
if (!homedir) {
struct passwd *pw = getpwuid(getuid());
homedir = pw->pw_dir;
}
#endif
char *basepath = malloc(strlen(homedir) + 12);
struct stat has_dir;

sprintf(basepath, "%s/.aeternum/", homedir);

if (lstat(basepath, &has_dir) == -1) {
if (errno == ENOENT) {
if (mkdir(basepath, 0755) == -1) {
perror("mkdir");
}
}
else {
return;
}
}

pidfile = malloc(snprintf(NULL, 0, "%s%s", basepath, pidname) + 1);
sprintf(pidfile, "%s%s", basepath, pidname);
free(basepath);
}

int main(int argc, char *argv[]) {
int r;
saneopt_t* opt;
Expand Down Expand Up @@ -227,15 +194,6 @@ int main(int argc, char *argv[]) {
opts.target = args[1];
opts.child_args = &args[1];

if (opts.pidname != NULL) {
if (strcspn(opts.pidname, "/") < strlen(opts.pidname))
pidfile = strdup(opts.pidname);
else set_pidfile_path(opts.pidname);
}
else {
set_pidfile_path(opts.target);
}

configure_stdio();

spawn_child(0);
Expand Down

0 comments on commit f63a9bb

Please sign in to comment.