Skip to content
Snippets Groups Projects
Commit f26c28f1 authored by Mikhail Kshevetskiy's avatar Mikhail Kshevetskiy Committed by Jakob Olsson
Browse files

fix bugs found during compilation with glibc

parent 3c915f5f
No related branches found
No related tags found
1 merge request!281fix bugs found during compilation with glibc
......@@ -10,7 +10,9 @@
#include <stdio.h>
#include <string.h>
#include <signal.h>
#ifndef __GLIBC__
#define __USE_XOPEN
#endif
#include <time.h>
#include <unistd.h>
#include <sys/types.h>
......@@ -491,13 +493,16 @@ void do_daemonize(const char *pidfile)
int f;
info("daemonizing ...\n");
daemon(0, 0);
if (daemon(0, 0)) {
fprintf(stderr, "Can't becomes a daemon. "
"Continue as foreground process...\n");
}
if (!pidfile)
return;
f = open(pidfile, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
if (f) {
if (f >= 0) {
flags = fcntl(f, F_GETFD);
if (flags != -1) {
flags |= FD_CLOEXEC;
......@@ -508,9 +513,17 @@ void do_daemonize(const char *pidfile)
pidfile);
exit(-1);
}
ftruncate(f, 0);
if (ftruncate(f, 0)) {
fprintf(stderr, "Continue with invalid pid file %s\n",
pidfile);
return;
}
snprintf(buf, sizeof(buf), "%ld\n", (long)getpid());
write(f, buf, strlen(buf));
if (write(f, buf, strlen(buf)) != strlen(buf)) {
fprintf(stderr, "Continue with invalid pid file %s\n",
pidfile);
return;
}
}
}
......@@ -640,7 +653,7 @@ int writeto_configfile(const char *filename, void *in, size_t len)
int fp;
fp = open(filename, O_WRONLY | O_CREAT);
fp = open(filename, O_WRONLY | O_CREAT, 0644);
if (fp < 0)
return -1;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment