[hackers] [ubase] Use SLIST instead of TAILQ for killall5(8) || sin

From: <git_AT_suckless.org>
Date: Wed, 7 Oct 2015 14:57:29 +0200 (CEST)

commit d3efa66c82d2e371b5813487e2c3ad9ef3100e6f
Author: sin <sin_AT_2f30.org>
AuthorDate: Wed Oct 7 14:50:38 2015 +0200
Commit: sin <sin_AT_2f30.org>
CommitDate: Wed Oct 7 13:57:24 2015 +0100

    Use SLIST instead of TAILQ for killall5(8)
    
    No need to teardown the list at the end.

diff --git a/killall5.c b/killall5.c
index e841841..14790b9 100644
--- a/killall5.c
+++ b/killall5.c
_AT_@ -24,10 +24,10 @@ struct {
 
 struct pidentry {
         pid_t pid;
- TAILQ_ENTRY(pidentry) entry;
+ SLIST_ENTRY(pidentry) entry;
 };
 
-static TAILQ_HEAD(omitpid_head, pidentry) omitpid_head;
+static SLIST_HEAD(, pidentry) omitpid_head;
 
 static void
 usage(void)
_AT_@ -38,7 +38,7 @@ usage(void)
 int
 main(int argc, char *argv[])
 {
- struct pidentry *pe, *tmp;
+ struct pidentry *pe;
         struct dirent *entry;
         DIR *dp;
         char *p, *arg = NULL;
_AT_@ -71,12 +71,12 @@ main(int argc, char *argv[])
                 usage();
         } ARGEND;
 
- TAILQ_INIT(&omitpid_head);
+ SLIST_INIT(&omitpid_head);
 
         for (p = strtok(arg, ","); p; p = strtok(NULL, ",")) {
                 pe = emalloc(sizeof(*pe));
                 pe->pid = estrtol(p, 10);
- TAILQ_INSERT_TAIL(&omitpid_head, pe, entry);
+ SLIST_INSERT_HEAD(&omitpid_head, pe, entry);
         }
 
         if (sig != SIGSTOP && sig != SIGCONT)
_AT_@ -92,7 +92,7 @@ main(int argc, char *argv[])
                     getsid(pid) == getsid(0) || getsid(pid) == 0)
                         continue;
                 if (oflag == 1) {
- TAILQ_FOREACH(pe, &omitpid_head, entry)
+ SLIST_FOREACH(pe, &omitpid_head, entry)
                                 if (pe->pid == pid)
                                         break;
                         if (pe)
_AT_@ -105,11 +105,5 @@ main(int argc, char *argv[])
         if (sig != SIGSTOP && sig != SIGCONT)
                 kill(-1, SIGCONT);
 
- for (pe = TAILQ_FIRST(&omitpid_head); pe; pe = tmp) {
- tmp = TAILQ_NEXT(pe, entry);
- TAILQ_REMOVE(&omitpid_head, pe, entry);
- free(pe);
- }
-
         return 0;
 }
Received on Wed Oct 07 2015 - 14:57:29 CEST

This archive was generated by hypermail 2.3.0 : Wed Oct 07 2015 - 15:00:13 CEST