]> git.sur5r.net Git - i3/i3status/blob - wmiistatus.c
a2c626ab5e535f7f1d8d69ca94587cebb90bd7b6
[i3/i3status] / wmiistatus.c
1 /*
2  * Generates a status line for use with wmii or other minimal window managers
3  *
4  *
5  * Copyright (c) 2008-2009 Michael Stapelberg and contributors
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without modification,
9  * are permitted provided that the following conditions are met:
10  *
11  * * Redistributions of source code must retain the above copyright notice, this
12  *   list of conditions and the following disclaimer.
13  *
14  * * Redistributions in binary form must reproduce the above copyright notice, this
15  *   list of conditions and the following disclaimer in the documentation and/or other
16  *   materials provided with the distribution.
17  *
18  * * Neither the name of Michael Stapelberg nor the names of contributors
19  *   may be used to endorse or promote products derived from this software without
20  *   specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
23  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25  * SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
27  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31  * DAMAGE.
32  *
33  */
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 #include <fcntl.h>
37 #include <string.h>
38 #include <stdio.h>
39 #include <time.h>
40 #include <stdbool.h>
41 #include <stdarg.h>
42 #include <unistd.h>
43 #include <stdlib.h>
44 #include <limits.h>
45 #include <ctype.h>
46 #include <net/if.h>
47 #include <sys/ioctl.h>
48 #include <sys/socket.h>
49 #include <netinet/in.h>
50 #include <arpa/inet.h>
51 #include <glob.h>
52 #include <dirent.h>
53 #include <getopt.h>
54
55 #ifdef LINUX
56 #include <linux/ethtool.h>
57 #include <linux/sockios.h>
58 #else
59 /* TODO: correctly check for *BSD */
60 #include <sys/param.h>
61 #include <sys/sysctl.h>
62 #include <sys/resource.h>
63 #endif
64
65 #define _IS_WMIISTATUS_C
66 #include "wmiistatus.h"
67 #undef _IS_WMIISTATUS_C
68
69 /* socket file descriptor for general purposes */
70 static int general_socket;
71
72 static const char *wlan_interface;
73 static const char *eth_interface;
74 static char *wmii_path;
75 static const char *time_format;
76 static const char *battery_path;
77 static bool use_colors;
78 static bool get_ethspeed;
79 static const char *wmii_normcolors = "#222222 #333333";
80 static char order[MAX_ORDER][2];
81 static const char **run_watches;
82 static unsigned int num_run_watches;
83 static unsigned int interval = 1;
84
85 /*
86  * This function just concats two strings in place, it should only be used
87  * for concatting order to the name of a file or concatting color codes.
88  * Otherwise, the buffer size would have to be increased.
89  *
90  */
91 static char *concat(const char *str1, const char *str2) {
92         static char concatbuf[32];
93         (void)snprintf(concatbuf, sizeof(concatbuf), "%s%s", str1, str2);
94         return concatbuf;
95 }
96
97 /*
98  * Cleans wmii's /rbar directory by deleting all regular files
99  *
100  */
101 static void cleanup_rbar_dir() {
102         struct dirent *ent;
103         DIR *dir;
104         char pathbuf[strlen(wmii_path)+256+1];
105
106         if ((dir = opendir(wmii_path)) == NULL)
107                 exit(EXIT_FAILURE);
108
109         while ((ent = readdir(dir)) != NULL) {
110                 if (ent->d_type == DT_REG) {
111                         (void)snprintf(pathbuf, sizeof(pathbuf), "%s%s", wmii_path, ent->d_name);
112                         if (unlink(pathbuf) == -1)
113                                 exit(EXIT_FAILURE);
114                 }
115         }
116
117         (void)closedir(dir);
118 }
119
120 /*
121  * Creates the specified file in wmii's /rbar directory with
122  * correct modes and initializes colors if colormode is enabled
123  *
124  */
125 static void create_file(const char *name) {
126         char pathbuf[strlen(wmii_path)+256+1];
127         int fd;
128         int flags = O_CREAT | O_WRONLY;
129         struct stat statbuf;
130
131         (void)snprintf(pathbuf, sizeof(pathbuf), "%s%s", wmii_path, name);
132
133         /* Overwrite file's contents if it exists */
134         if (stat(pathbuf, &statbuf) >= 0)
135                 flags |= O_TRUNC;
136
137         if ((fd = open(pathbuf, flags, S_IRUSR | S_IWUSR)) < 0)
138                 exit(EXIT_FAILURE);
139         if (use_colors) {
140                 char *tmp = concat("#888888 ", wmii_normcolors);
141                 if (write(fd, tmp, strlen(tmp)) != (ssize_t)strlen(tmp))
142                         exit(EXIT_FAILURE);
143         }
144         (void)close(fd);
145 }
146
147 /*
148  * Waits until wmii_path/rbar exists (= the filesystem gets mounted),
149  * cleans up all files and creates the needed files
150  *
151  */
152 static void setup(void) {
153         unsigned int i;
154         struct stat statbuf;
155         char pathbuf[512];
156
157         /* Wait until wmii_path/rbar exists */
158         for (; stat(wmii_path, &statbuf) < 0; sleep(interval));
159
160         cleanup_rbar_dir();
161         if (wlan_interface)
162                 create_file(concat(order[ORDER_WLAN],"wlan"));
163         if (eth_interface)
164                 create_file(concat(order[ORDER_ETH],"eth"));
165         if (battery_path)
166                 create_file(concat(order[ORDER_BATTERY],"battery"));
167         create_file(concat(order[ORDER_LOAD],"load"));
168         if (time_format)
169                 create_file(concat(order[ORDER_TIME],"time"));
170         for (i = 0; i < num_run_watches; i += 2) {
171                 snprintf(pathbuf, sizeof(pathbuf), "%s%s", order[ORDER_RUN], run_watches[i]);
172                 create_file(pathbuf);
173         }
174 }
175
176 /*
177  * Writes the given message in the corresponding file in wmii's /rbar directory
178  *
179  */
180 static void write_to_statusbar(const char *name, const char *message) {
181         char pathbuf[strlen(wmii_path)+256+1];
182         int fd;
183
184         (void)snprintf(pathbuf, sizeof(pathbuf), "%s%s", wmii_path, name);
185         if ((fd = open(pathbuf, O_RDWR)) == -1) {
186                 /* Try to re-setup stuff and just continue */
187                 setup();
188                 return;
189         }
190         if (write(fd, message, strlen(message)) != (ssize_t)strlen(message))
191                 exit(EXIT_FAILURE);
192         (void)close(fd);
193 }
194
195 /*
196  * Writes an errormessage to statusbar
197  *
198  */
199 static void write_error_to_statusbar(const char *message) {
200         cleanup_rbar_dir();
201         create_file("error");
202         write_to_statusbar("error", message);
203 }
204
205 /*
206  * Write errormessage to statusbar and exit
207  *
208  */
209 void die(const char *fmt, ...) {
210         if (wmii_path != NULL) {
211                 char buffer[512];
212                 va_list ap;
213                 va_start(ap, fmt);
214                 (void)vsnprintf(buffer, sizeof(buffer), fmt, ap);
215                 va_end(ap);
216
217                 write_error_to_statusbar(buffer);
218         }
219         exit(EXIT_FAILURE);
220 }
221
222 /*
223  * Skip the given character for exactly 'amount' times, returns
224  * a pointer to the first non-'character' character in 'input'.
225  *
226  */
227 static char *skip_character(char *input, char character, int amount) {
228         char *walk;
229         size_t len = strlen(input);
230         int blanks = 0;
231
232         for (walk = input; ((size_t)(walk - input) < len) && (blanks < amount); walk++)
233                 if (*walk == character)
234                         blanks++;
235
236         return (walk == input ? walk : walk-1);
237 }
238
239 /*
240  * Get battery information from /sys. Note that it uses the design capacity to
241  * calculate the percentage, not the last full capacity, so you can see how
242  * worn off your battery is.
243  *
244  */
245 static char *get_battery_info() {
246         char buf[1024];
247         static char part[512];
248         char *walk, *last;
249         int fd;
250         int full_design = -1,
251             remaining = -1,
252             present_rate = -1;
253         charging_status_t status = CS_DISCHARGING;
254
255         if ((fd = open(battery_path, O_RDONLY)) == -1)
256                 return "No battery found";
257
258         memset(part, 0, sizeof(part));
259         (void)read(fd, buf, sizeof(buf));
260         for (walk = buf, last = buf; (walk-buf) < 1024; walk++)
261                 if (*walk == '=') {
262                         if (BEGINS_WITH(last, "POWER_SUPPLY_ENERGY_FULL_DESIGN") ||
263                             BEGINS_WITH(last, "POWER_SUPPLY_CHARGE_FULL_DESIGN"))
264                                 full_design = atoi(walk+1);
265                         else if (BEGINS_WITH(last, "POWER_SUPPLY_ENERGY_NOW") ||
266                                  BEGINS_WITH(last, "POWER_SUPPLY_CHARGE_NOW"))
267                                 remaining = atoi(walk+1);
268                         else if (BEGINS_WITH(last, "POWER_SUPPLY_CURRENT_NOW"))
269                                 present_rate = atoi(walk+1);
270                         else if (BEGINS_WITH(last, "POWER_SUPPLY_STATUS=Charging"))
271                                 status = CS_CHARGING;
272                         else if (BEGINS_WITH(last, "POWER_SUPPLY_STATUS=Full"))
273                                 status = CS_FULL;
274                 } else if (*walk == '\n')
275                         last = walk+1;
276         (void)close(fd);
277
278         if ((full_design != -1) && (remaining != -1) && (present_rate != -1)) {
279                 float remaining_time;
280                 int seconds, hours, minutes;
281                 if (status == CS_CHARGING)
282                         remaining_time = ((float)full_design - (float)remaining) / (float)present_rate;
283                 else if (status == CS_DISCHARGING)
284                         remaining_time = ((float)remaining / (float)present_rate);
285                 else remaining_time = 0;
286
287                 seconds = (int)(remaining_time * 3600.0);
288                 hours = seconds / 3600;
289                 seconds -= (hours * 3600);
290                 minutes = seconds / 60;
291                 seconds -= (minutes * 60);
292
293                 (void)snprintf(part, sizeof(part), "%s %.02f%% %02d:%02d:%02d",
294                         (status == CS_CHARGING ? "CHR" :
295                          (status == CS_DISCHARGING ? "BAT" : "FULL")),
296                         (((float)remaining / (float)full_design) * 100),
297                         hours, minutes, seconds);
298         }
299         return part;
300 }
301
302 /*
303  * Return the IP address for the given interface or "no IP" if the
304  * interface is up and running but hasn't got an IP address yet
305  *
306  */
307 static const char *get_ip_address(const char *interface) {
308         static char part[512];
309         struct ifreq ifr;
310         struct sockaddr_in addr;
311         socklen_t len = sizeof(struct sockaddr_in);
312         memset(part, 0, sizeof(part));
313
314         (void)strcpy(ifr.ifr_name, interface);
315         ifr.ifr_addr.sa_family = AF_INET;
316         if (ioctl(general_socket, SIOCGIFADDR, &ifr) < 0)
317                 return NULL;
318
319         memcpy(&addr, &ifr.ifr_addr, len);
320         (void)inet_ntop(AF_INET, &addr.sin_addr.s_addr, part, len);
321         if (strlen(part) == 0)
322                 (void)snprintf(part, sizeof(part), "no IP");
323
324         return part;
325 }
326
327 /*
328  * Just parses /proc/net/wireless looking for lines beginning with
329  * wlan_interface, extracting the quality of the link and adding the
330  * current IP address of wlan_interface.
331  *
332  */
333 static char *get_wireless_info() {
334         char buf[1024];
335         static char part[512];
336         char *interfaces;
337         int fd;
338         memset(buf, 0, sizeof(buf));
339         memset(part, 0, sizeof(part));
340
341         if ((fd = open("/proc/net/wireless", O_RDONLY)) == -1)
342                 die("Could not open /proc/net/wireless\n");
343         (void)read(fd, buf, sizeof(buf));
344         (void)close(fd);
345
346         interfaces = skip_character(buf, '\n', 1) + 1;
347         while ((interfaces = skip_character(interfaces, '\n', 1)+1) < buf+strlen(buf)) {
348                 while (isspace((int)*interfaces))
349                         interfaces++;
350                 if (!BEGINS_WITH(interfaces, wlan_interface))
351                         continue;
352                 int quality;
353                 if (sscanf(interfaces, "%*[^:]: 0000 %d", &quality) != 1)
354                         continue;
355                 if ((quality == UCHAR_MAX) || (quality == 0)) {
356                         if (use_colors)
357                                 (void)snprintf(part, sizeof(part), "%s%s",
358                                         concat("#FF0000 ", wmii_normcolors), " W: down");
359                         else (void)snprintf(part, sizeof(part), "W: down");
360                 } else (void)snprintf(part, sizeof(part), "W: (%03d%%) %s",
361                                 quality, get_ip_address(wlan_interface));
362                 return part;
363         }
364
365         return part;
366 }
367
368 /*
369  * Combines ethernet IP addresses and speed (if requested) for displaying
370  *
371  */
372 static char *get_eth_info() {
373         static char part[512];
374         const char *ip_address = get_ip_address(eth_interface);
375         int ethspeed = 0;
376
377         if (get_ethspeed) {
378 #ifdef LINUX
379                 /* This code path requires root privileges */
380                 struct ifreq ifr;
381                 struct ethtool_cmd ecmd;
382
383                 ecmd.cmd = ETHTOOL_GSET;
384                 (void)memset(&ifr, 0, sizeof(ifr));
385                 ifr.ifr_data = (caddr_t)&ecmd;
386                 (void)strcpy(ifr.ifr_name, eth_interface);
387                 if (ioctl(general_socket, SIOCETHTOOL, &ifr) == 0)
388                         ethspeed = (ecmd.speed == USHRT_MAX ? 0 : ecmd.speed);
389                 else get_ethspeed = false;
390 #endif
391         }
392
393         if (ip_address == NULL)
394                 (void)snprintf(part, sizeof(part), "E: down");
395         else {
396                 if (get_ethspeed)
397                         (void)snprintf(part, sizeof(part), "E: %s (%d Mbit/s)", ip_address, ethspeed);
398                 else (void)snprintf(part, sizeof(part), "E: %s", ip_address);
399         }
400
401         return part;
402 }
403
404 /*
405  * Checks if the PID in path is still valid by checking:
406  *  (Linux) if /proc/<pid> exists
407  *  (NetBSD) if sysctl returns process infos for this pid
408  *
409  */
410 static bool process_runs(const char *path) {
411         char pidbuf[16];
412         static glob_t globbuf;
413         int fd;
414         memset(pidbuf, 0, sizeof(pidbuf));
415
416         if (glob(path, GLOB_NOCHECK | GLOB_TILDE, NULL, &globbuf) < 0)
417                 die("glob() failed\n");
418         fd = open((globbuf.gl_pathc > 0 ? globbuf.gl_pathv[0] : path), O_RDONLY);
419         globfree(&globbuf);
420         if (fd < 0)
421                 return false;
422         (void)read(fd, pidbuf, sizeof(pidbuf));
423         (void)close(fd);
424
425 #ifdef LINUX
426         struct stat statbuf;
427         char procbuf[512];
428         (void)snprintf(procbuf, sizeof(procbuf), "/proc/%ld", strtol(pidbuf, NULL, 10));
429         return (stat(procbuf, &statbuf) >= 0);
430 #else
431         /* TODO: correctly check for NetBSD. Evaluate if this runs on OpenBSD/FreeBSD */
432         struct kinfo_proc info;
433         size_t length = sizeof(struct kinfo_proc);
434         int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, strtol(pidbuf, NULL, 10) };
435         if (sysctl(mib, 4, &info, &length, NULL, 0) < 0)
436                 return false;
437         return (length != 0);
438 #endif
439 }
440
441 /*
442  * Reads the configuration from the given file
443  *
444  */
445 static int load_configuration(const char *configfile) {
446         #define OPT(x) else if (strcasecmp(dest_name, x) == 0)
447
448         /* check if the file exists */
449         struct stat buf;
450         if (stat(configfile, &buf) < 0)
451                 return -1;
452
453         int result = 0;
454         FILE *handle = fopen(configfile, "r");
455         if (handle == NULL)
456                 die("Could not open configfile\n");
457         char dest_name[512], dest_value[512], whole_buffer[1026];
458         struct stat stbuf;
459         while (!feof(handle)) {
460                 char *ret;
461                 if ((ret = fgets(whole_buffer, 1024, handle)) == whole_buffer) {
462                         /* sscanf implicitly strips whitespace */
463                         if (sscanf(whole_buffer, "%s %[^\n]", dest_name, dest_value) < 1)
464                                 continue;
465                 } else if (ret != NULL)
466                         die("Could not read line in configuration file\n");
467
468                 /* skip comments and empty lines */
469                 if (dest_name[0] == '#' || strlen(dest_name) < 3)
470                         continue;
471
472                 OPT("wlan")
473                         wlan_interface = strdup(dest_value);
474                 OPT("eth")
475                         eth_interface = strdup(dest_value);
476                 OPT("time_format")
477                         time_format = strdup(dest_value);
478                 OPT("battery_path")
479                         battery_path = strdup(dest_value);
480                 OPT("color")
481                         use_colors = true;
482                 OPT("get_ethspeed")
483                         get_ethspeed = true;
484                 OPT("normcolors")
485                         wmii_normcolors = strdup(dest_value);
486                 OPT("interval")
487                         interval = atoi(dest_value);
488                 OPT("wmii_path")
489                 {
490                         static glob_t globbuf;
491                         if (glob(dest_value, GLOB_NOCHECK | GLOB_TILDE, NULL, &globbuf) < 0)
492                                 die("glob() failed\n");
493                         wmii_path = strdup(globbuf.gl_pathc > 0 ? globbuf.gl_pathv[0] : dest_value);
494                         globfree(&globbuf);
495
496                         if ((stat(wmii_path, &stbuf)) == -1) {
497                                 fprintf(stderr, "Warning: wmii_path contains an invalid path\n");
498                                 free(wmii_path);
499                                 wmii_path = strdup(dest_value);
500                         }
501                         if (wmii_path[strlen(wmii_path)-1] != '/')
502                                 die("wmii_path is not terminated by /\n");
503                 }
504                 OPT("run_watch")
505                 {
506                         char *name = strdup(dest_value);
507                         char *path = name;
508                         while (*path != ' ')
509                                 path++;
510                         *(path++) = '\0';
511                         num_run_watches += 2;
512                         run_watches = realloc(run_watches, sizeof(char*) * num_run_watches);
513                         run_watches[num_run_watches-2] = name;
514                         run_watches[num_run_watches-1] = path;
515                 }
516                 OPT("order")
517                 {
518                         #define SET_ORDER(opt, idx) { if (strcasecmp(token, opt) == 0) sprintf(order[idx], "%d", c++); }
519                         char *walk, *token;
520                         int c = 0;
521                         walk = token = dest_value;
522                         while (*walk != '\0') {
523                                 while ((*walk != ',') && (*walk != '\0'))
524                                         walk++;
525                                 *(walk++) = '\0';
526                                 SET_ORDER("run", ORDER_RUN);
527                                 SET_ORDER("wlan", ORDER_WLAN);
528                                 SET_ORDER("eth", ORDER_ETH);
529                                 SET_ORDER("battery", ORDER_BATTERY);
530                                 SET_ORDER("load", ORDER_LOAD);
531                                 SET_ORDER("time", ORDER_TIME);
532                                 token = walk;
533                                 while (isspace((int)(*token)))
534                                         token++;
535                         }
536                 }
537                 else
538                 {
539                         result = -2;
540                         die("Unknown configfile option: %s\n", dest_name);
541                 }
542         }
543         fclose(handle);
544
545         if (wmii_path == NULL)
546                 exit(EXIT_FAILURE);
547
548         return result;
549 }
550
551 int main(int argc, char *argv[]) {
552         char part[512],
553              pathbuf[512];
554         unsigned int i;
555
556         char *configfile = PREFIX "/etc/wmiistatus.conf";
557         int o, option_index = 0;
558         struct option long_options[] = {
559                 {"config", required_argument, 0, 'c'},
560                 {"help", no_argument, 0, 'h'},
561                 {0, 0, 0, 0}
562         };
563
564         while ((o = getopt_long(argc, argv, "c:h", long_options, &option_index)) != -1)
565                 if ((char)o == 'c')
566                         configfile = optarg;
567                 else if ((char)o == 'h') {
568                         printf("wmiistatus (c) 2008-2009 Michael Stapelberg\n"
569                                 "Syntax: %s [-c <configfile>]\n", argv[0]);
570                         return 0;
571                 }
572
573         if (load_configuration(configfile) < 0)
574                 return EXIT_FAILURE;
575
576         setup();
577
578         if ((general_socket = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
579                 die("Could not create socket\n");
580
581         while (1) {
582                 for (i = 0; i < num_run_watches; i += 2) {
583                         bool running = process_runs(run_watches[i+1]);
584                         if (use_colors)
585                                 snprintf(part, sizeof(part), "%s %s: %s",
586                                         (running ?
587                                                 concat("#00FF00 ", wmii_normcolors) :
588                                                 concat("#FF0000 ", wmii_normcolors)),
589                                         run_watches[i],
590                                         (running ? "yes" : "no"));
591                         else snprintf(part, sizeof(part), "%s: %s", run_watches[i], (running ? "yes" : "no"));
592                         snprintf(pathbuf, sizeof(pathbuf), "%s%s", order[ORDER_RUN], run_watches[i]);
593                         write_to_statusbar(pathbuf, part);
594                 }
595
596                 if (wlan_interface)
597                         write_to_statusbar(concat(order[ORDER_WLAN], "wlan"), get_wireless_info());
598                 if (eth_interface)
599                         write_to_statusbar(concat(order[ORDER_ETH], "eth"), get_eth_info());
600                 if (battery_path)
601                         write_to_statusbar(concat(order[ORDER_BATTERY], "battery"), get_battery_info());
602
603                 /* Get load */
604 #ifdef LINUX
605                 int load_avg;
606                 if ((load_avg = open("/proc/loadavg", O_RDONLY)) == -1)
607                         die("Could not open /proc/loadavg\n");
608                 (void)read(load_avg, part, sizeof(part));
609                 (void)close(load_avg);
610                 *skip_character(part, ' ', 3) = '\0';
611 #else
612                 /* TODO: correctly check for NetBSD, check if it works the same on *BSD */
613                 struct loadavg load;
614                 size_t length = sizeof(struct loadavg);
615                 int mib[2] = { CTL_VM, VM_LOADAVG };
616                 if (sysctl(mib, 2, &load, &length, NULL, 0) < 0)
617                         die("Could not sysctl({ CTL_VM, VM_LOADAVG })\n");
618                 double scale = load.fscale;
619                 (void)snprintf(part, sizeof(part), "%.02f %.02f %.02f",
620                                 (double)load.ldavg[0] / scale,
621                                 (double)load.ldavg[1] / scale,
622                                 (double)load.ldavg[2] / scale);
623 #endif
624                 write_to_statusbar(concat(order[ORDER_LOAD], "load"), part);
625
626                 if (time_format) {
627                         /* Get date & time */
628                         time_t current_time = time(NULL);
629                         struct tm *current_tm = localtime(&current_time);
630                         (void)strftime(part, sizeof(part), time_format, current_tm);
631                         write_to_statusbar(concat(order[ORDER_TIME], "time"), part);
632                 }
633
634                 sleep(interval);
635         }
636 }