lanoxx / tilda

A Gtk based drop down terminal for Linux and Unix
GNU General Public License v2.0
1.28k stars 161 forks source link

Tilda help show ps(1) error #282

Open Avispa opened 7 years ago

Avispa commented 7 years ago

tilda --help, and others probably as well -- version for example, shows ps(1) error.

> tilda --help
ps: illegal argument: tilda
usage: ps [-aCcdefHhjlmrSTuvwXxZ] [-O fmt | -o fmt] [-G gid[,gid...]]
          [-J jid[,jid...]] [-M core] [-N system]
          [-p pid[,pid...]] [-t tty[,tty...]] [-U user[,user...]]
       ps [-L]
Aufruf:
  tilda [OPTION ?]
(...)

PS: A manpage (man(1)) would be neat anyhow.

gzip4 commented 7 years ago
--- tilda.c.orig    2017-09-17 14:29:53.223379000 +0500
+++ tilda.c 2017-09-17 14:58:33.195631000 +0500
@@ -231,7 +231,7 @@
 static GSList *getPids() {
     GSList *pids = NULL;
     FILE *ps_output;
-    const gchar ps_command[] = "ps -C tilda -o pid=";
+    const gchar ps_command[] = "pgrep -a tilda";
     gchar buf[16]; /* Really shouldn't need more than 6 */

     if ((ps_output = popen (ps_command, "r")) == NULL) {
lanoxx commented 6 years ago

If we change this, then lets use something that is POSIX compliant and will work on all systems.

How about:

-    const gchar ps_command[] = "ps -C tilda -o pid=";
+    const gchar ps_command[] = "ps -Aocomm=,pid=,etime= | "
                                "sed -ne \"s/^tilda  *//p\"";
lanoxx commented 6 years ago

See also: https://unix.stackexchange.com/questions/234709/avoid-pgrep-in-sh

Avispa commented 6 years ago

Without knowing the code or the background of the code but wouldn't it better to just call the appropriate C function than some "funky" programs? (For example: pid_t getpid(void);.)

cypa commented 6 years ago

@lanoxx, it works in busibox's ash indeed