Skip to content
Snippets Groups Projects
Commit 25f75ec5 authored by Roman Tokarev's avatar Roman Tokarev
Browse files

Fixes to compile on FreeBSD.

 - Replace strndrupa with alloca + memcpy.
 - In create_pid function do rewind before read from pid file.
parent a6c1f381
No related branches found
No related tags found
No related merge requests found
......@@ -576,7 +576,9 @@ inprogress_log_rename(char *filename)
assert(strcmp(suffix, inprogress_suffix) == 0);
/* Create a new filename without '.inprogress' suffix. */
new_filename = strndupa(filename, suffix - filename);
new_filename = alloca(suffix - filename + 1);
memcpy(new_filename, filename, suffix - filename);
new_filename[suffix - filename] = '\0';
if (rename(filename, new_filename) != 0) {
say_syserror("can't rename %s to %s", filename, new_filename);
......
......@@ -267,6 +267,13 @@ create_pid(void)
f = fopen(cfg.pid_file, "a+");
if (f == NULL)
panic_syserror("can't open pid file");
/*
* fopen() is not guaranteed to set the seek position to
* the beginning of file according to ANSI C (and, e.g.,
* on FreeBSD.
*/
if (fseeko(f, 0, SEEK_SET) != 0)
panic_syserror("can't fseek to the beginning of pid file");
if (fgets(buf, sizeof(buf), f) != NULL && strlen(buf) > 0) {
pid = strtol(buf, NULL, 10);
......@@ -274,7 +281,8 @@ create_pid(void)
panic("the daemon is already running");
else
say_info("updating a stale pid file");
fseeko(f, 0, SEEK_SET);
if (fseeko(f, 0, SEEK_SET) != 0)
panic_syserror("can't fseek to the beginning of pid file");
if (ftruncate(fileno(f), 0) == -1)
panic_syserror("ftruncate(`%s')", cfg.pid_file);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment