[PATCH] deluser patch 02

Tito farmatito at tiscali.it
Thu Nov 30 07:47:23 UTC 2006


On Thursday 30 November 2006 00:49, Denis Vlasenko wrote:
> On Wednesday 29 November 2006 20:50, Tito wrote:
> > Hi Denis,
> > This patch modifies the ENABLE_FEATURE_CLEAN_UP stuff in deluser so that it is not
> > necessary to duplicate the code and adds ENABLE_FEATURE_CLEAN_UP in a few
> > more places to be coherent thus saving some size.
> > Please take a look at it and apply it if
> > you like it.
> 
> After trying several ways to write it, i decided to code
> ENABLE_FEATURE_CLEAN_UP and !ENABLE_FEATURE_CLEAN_UP versions
> completely separated. Only one is compiled into binary anyway,
> so there is no risk of code duplication.
> 
> But it is _much_ easier to review.
> 
> Current svn:
> 
> ...
>         if (!ENABLE_FEATURE_CLEAN_UP) {
>                 if (!found) {
>                         bb_error_msg("can't find '%s' in '%s'", login, filename);
>                         return;
>                 }
>                 passwd = fopen_or_warn(filename, "w");
>                 if (passwd)
>                         while ((line = llist_pop(&plist)))
>                                 fputs(line, passwd);
>         } else {
>                 if (!found) {
>                         bb_error_msg("can't find '%s' in '%s'", login, filename);
>                         goto clean_up;
>                 }
>                 fclose(passwd);
>                 passwd = fopen_or_warn(filename, "w");
>                 if (passwd) {
>  clean_up:
>                         while ((line = llist_pop(&plist))) {
>                                 if (found) fputs(line, passwd);
>                                 free(line);
>                         }
>                         fclose(passwd);
>                 }
>         }
> }
> 
> Is it good enough? Entire file is attached.

Looks good to me if you prefer it this way. Just for coherence:

	while ((line = xmalloc_fgets(passwd))) {
		if (!strncmp(line, login, len)
		 && line[len] == ':'
		) {
			found++;
-			free(line);
+                     if (ENABLE__FEATURE_CLEAN_UP) free (line);
		} else {
			llist_add_to_end(&plist, line);
		}
	}

Ciao,
Tito


> --
> vda
> 



More information about the busybox mailing list