1
0
Fork 0
mirror of https://github.com/kakwa/uts-server synced 2025-07-04 12:37:08 +02:00

fix the way relative paths are handled and pid file handler

* add a pid file option on command line + implement it
* make the relative path in conf param relative to the configuration
  file directory and not the running directory
This commit is contained in:
kakwa 2016-09-01 19:43:29 +02:00
parent 5cbcdc4a1d
commit a3f65c7050
3 changed files with 80 additions and 6 deletions

View file

@ -10,6 +10,8 @@
#include <errno.h>
#include <string.h>
#include <syslog.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "utils.h"
typedef struct _code {
@ -38,6 +40,47 @@ static void signal_handler_up(int sig_num) {
g_uts_sig_up = sig_num;
}
int init_pid(char *pidfile_path) {
// if pidfile_path is null, the user did not request one
// exit success
if (pidfile_path == NULL)
return 1;
int fd = open(pidfile_path, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
// in case we can't open it
if (fd == -1) {
syslog(LOG_CRIT, "failed to open the pid file");
return 0;
}
close(fd);
return 1;
}
int write_pid(char *pidfile_path) {
// if pidfile_path is null, the user did not request one
// exit success
if (pidfile_path == NULL)
return 1;
int fd = open(pidfile_path, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
// in case we can't open it
if (fd == -1) {
syslog(LOG_CRIT, "failed to open the pid file");
return 0;
}
char buf[100];
snprintf(buf, 100, "%ld\n", (long)getpid());
if (write(fd, buf, strlen(buf)) != strlen(buf)) {
syslog(LOG_CRIT, "failed to write the pid");
close(fd);
return 0;
}
close(fd);
return 1;
}
void skeleton_daemon() {
pid_t pid;