Patchwork [1/2] ulogd: Perform nice() before giving up root

login
register
mail settings
Submitter Chris Boot
Date May 11, 2013, 5:01 p.m.
Message ID <1368291713-40132-2-git-send-email-bootc@bootc.net>
Download mbox | patch
Permalink /patch/243144/
State Accepted
Headers show

Comments

Chris Boot - May 11, 2013, 5:01 p.m.
The daemon code currently tries to nice(-1) just after having given up root
privileges, which fails. This patch moves the nice(-1) call to just before
the code that gives up the required privileges.

Signed-off-by: Chris Boot <bootc@bootc.net>
---
 src/ulogd.c |   14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
Chris Boot - May 17, 2013, 7:34 a.m.
On 11/05/13 18:01, Chris Boot wrote:
> The daemon code currently tries to nice(-1) just after having given up root
> privileges, which fails. This patch moves the nice(-1) call to just before
> the code that gives up the required privileges.
>
> Signed-off-by: Chris Boot <bootc@bootc.net>
> ---
>  src/ulogd.c |   14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/src/ulogd.c b/src/ulogd.c
> index b28d0f8..8a144e3 100644
> --- a/src/ulogd.c
> +++ b/src/ulogd.c
> @@ -1235,6 +1235,13 @@ int main(int argc, char* argv[])
>  		warn_and_exit(daemonize);
>  	}
>  
> +	errno = 0;
> +	if (nice(-1) == -1) {
> +		if (errno != 0)
> +			ulogd_log(ULOGD_ERROR, "Could not nice process: %s\n",
> +				  strerror(errno));
> +	}
> +
>  	if (change_uid) {
>  		ulogd_log(ULOGD_NOTICE, "Changing UID / GID\n");
>  		if (setgid(gid)) {
> @@ -1261,13 +1268,6 @@ int main(int argc, char* argv[])
>  		}
>  	}
>  
> -	errno = 0;
> -	if (nice(-1) == -1) {
> -		if (errno != 0)
> -			ulogd_log(ULOGD_ERROR, "Could not nice process: %s\n",
> -				  strerror(errno));
> -	}
> -
>  
>  	if (daemonize){
>  		if (fork()) {

Hi all,

I have had no comments about this patch since I submitted it; is it
likely to get pulled into ulogd?

Cheers,
Chris
Eric Leblond - May 17, 2013, 8:28 a.m.
Hi,

On Fri, 2013-05-17 at 08:34 +0100, Chris Boot wrote:
> On 11/05/13 18:01, Chris Boot wrote:
> > The daemon code currently tries to nice(-1) just after having given up root
> > privileges, which fails. This patch moves the nice(-1) call to just before
> > the code that gives up the required privileges.
> >
> > Signed-off-by: Chris Boot <bootc@bootc.net>
> > ---
> >  src/ulogd.c |   14 +++++++-------
> >  1 file changed, 7 insertions(+), 7 deletions(-)
> >
> > diff --git a/src/ulogd.c b/src/ulogd.c
> > index b28d0f8..8a144e3 100644
> > --- a/src/ulogd.c
> > +++ b/src/ulogd.c
> > @@ -1235,6 +1235,13 @@ int main(int argc, char* argv[])
> >  		warn_and_exit(daemonize);
> >  	}
> >  
> > +	errno = 0;
> > +	if (nice(-1) == -1) {
> > +		if (errno != 0)
> > +			ulogd_log(ULOGD_ERROR, "Could not nice process: %s\n",
> > +				  strerror(errno));
> > +	}
> > +
> >  	if (change_uid) {
> >  		ulogd_log(ULOGD_NOTICE, "Changing UID / GID\n");
> >  		if (setgid(gid)) {
> > @@ -1261,13 +1268,6 @@ int main(int argc, char* argv[])
> >  		}
> >  	}
> >  
> > -	errno = 0;
> > -	if (nice(-1) == -1) {
> > -		if (errno != 0)
> > -			ulogd_log(ULOGD_ERROR, "Could not nice process: %s\n",
> > -				  strerror(errno));
> > -	}
> > -
> >  
> >  	if (daemonize){
> >  		if (fork()) {
> 
> Hi all,
> 
> I have had no comments about this patch since I submitted it; is it
> likely to get pulled into ulogd?

Yes, it seems ok. I will give it some tests but it should be applied.

BR,

> 
> Cheers,
> Chris
>

Patch

diff --git a/src/ulogd.c b/src/ulogd.c
index b28d0f8..8a144e3 100644
--- a/src/ulogd.c
+++ b/src/ulogd.c
@@ -1235,6 +1235,13 @@  int main(int argc, char* argv[])
 		warn_and_exit(daemonize);
 	}
 
+	errno = 0;
+	if (nice(-1) == -1) {
+		if (errno != 0)
+			ulogd_log(ULOGD_ERROR, "Could not nice process: %s\n",
+				  strerror(errno));
+	}
+
 	if (change_uid) {
 		ulogd_log(ULOGD_NOTICE, "Changing UID / GID\n");
 		if (setgid(gid)) {
@@ -1261,13 +1268,6 @@  int main(int argc, char* argv[])
 		}
 	}
 
-	errno = 0;
-	if (nice(-1) == -1) {
-		if (errno != 0)
-			ulogd_log(ULOGD_ERROR, "Could not nice process: %s\n",
-				  strerror(errno));
-	}
-
 
 	if (daemonize){
 		if (fork()) {