Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close stdin / stdout / stderr in child process after fork #7

Merged
merged 3 commits into from
Apr 14, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions god.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>

void usage() {
printf(
Expand Down Expand Up @@ -61,6 +62,7 @@ int main(int argc, char **argv) {
char user[64];
char group[64];
int foreground = 0;
struct stat exec_stat;

memset(logfile, 0, sizeof logfile);
memset(pidfile, 0, sizeof pidfile);
Expand Down Expand Up @@ -163,6 +165,17 @@ int main(int argc, char **argv) {
return 1;
}

if (stat(argv[optind], &exec_stat) < 0) {
fprintf(stderr, "failed to stat %s: %s\n",
argv[optind], strerror(errno));
return 1;
}
if (!(exec_stat.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))) {
fprintf(stderr, "file %s doesn't look executable\n",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Print Permission denied instead.

argv[optind]);
return 1;
}

if (foreground) {
daemon_main(optind, argv);
} else {
Expand Down