[BusyBox] [patch] pidof, make -s optional and add optional -o

Vladimir N. Oleynik dzo at simtreas.ru
Mon Feb 21 09:30:24 UTC 2005


Bernhard,

> #define _OMIT(a) a
> #define _OMIT_COMPLEMENT "o*"
> #else
> #define _OMIT_COMPLEMENT(a)
> #endif
> better?

Yes.

>>>+	omits_p->data = strtol(omits_p->data, NULL, 10);
>>
>>>+	if (omits_p->data == *pl) { omitted = 1;
>>
>>Hmm. Its not tested? data is (void *) and convert to (long) is not 
>>portabily.
> 
> it wasn't, really. would a cast suffice in your opinion? If not,
> cleaner way?

(cast) too will be bad idea. In fact thus you write down garbage
in memory of arguments of the program, creating a problem to other
procps utilities. ;-)

I would make so:

#ifdef CONFIG_FEATURE_PIDOF_OMIT
  /* fill omit list */
  {
+ char getppid_str[32];
...
-  if (!strncmp(omits_p->data, "%PPID", 5))
-   omits_p->data = getppid();
+  if (!strncmp(omits_p->data, "%PPID", 5)) {
+   snprintf(getpid_str, sizeof(getpid_str), "%ld", getppid());
+   omits_p->data = getppid_str;
...
-   } else
-     omits_p->data = strtol(omits_p->data, NULL, 10);
+   }
...
    while ((opt & OMIT) && omits_p)
-    if (omits_p->data == *pl) { omitted = 1; break; }
+    if (strtol(omits_p->data, NULL, 10) == *pl) { omitted = 1; break; }



--w
vodz



More information about the busybox mailing list