Skip to content

Commit

Permalink
Avoid chown on PID and PGID files in debug mode
Browse files Browse the repository at this point in the history
In debug mode, these files are not created in debug mode (as daemonize() is not triggered), so any chown() will simply fail on it.

(cherry picked from commit 15a0ea7)
  • Loading branch information
bogdan-iancu committed Mar 30, 2017
1 parent 59baf85 commit 3a0a8e1
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions daemonize.c
Expand Up @@ -391,24 +391,28 @@ int daemonize(char* name, int * own_pgid)
*/
int do_suid(const int uid, const int gid)
{
if (pid_file) {
/* pid file should be already created by deamonize function
-> change the owner and group also
*/
if (chown( pid_file , uid?uid:-1, gid?gid:-1)!=0) {
LM_ERR("failed to change owner of pid file %s: %s(%d)\n",
pid_file, strerror(errno), errno);
goto error;
/* if running in debug mode, do not do anything about the PID file
* as they are not created (daemonize() is not used in debug mode) */
if (!debug_mode) {
if (pid_file) {
/* pid file should be already created by deamonize function
-> change the owner and group also
*/
if (chown( pid_file , uid?uid:-1, gid?gid:-1)!=0) {
LM_ERR("failed to change owner of pid file %s: %s(%d)\n",
pid_file, strerror(errno), errno);
goto error;
}
}
}
if (pgid_file) {
/* pgid file should be already created by deamonize function
-> change the owner and group also
*/
if (chown( pgid_file , uid?uid:-1, gid?gid:-1)!=0) {
LM_ERR("failed to change owner of pid file %s: %s(%d)\n",
pgid_file, strerror(errno), errno);
goto error;
if (pgid_file) {
/* pgid file should be already created by deamonize function
-> change the owner and group also
*/
if (chown( pgid_file , uid?uid:-1, gid?gid:-1)!=0) {
LM_ERR("failed to change owner of pid file %s: %s(%d)\n",
pgid_file, strerror(errno), errno);
goto error;
}
}
}

Expand Down

0 comments on commit 3a0a8e1

Please sign in to comment.