From 9388ee56e183ccb0210f6ee03bdb2f4ee9f3ebcf Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sun, 30 Nov 2008 01:46:01 +0100 Subject: [PATCH] Correctly open new files --- wmiistatus.c | 9 ++++++++- wmiistatus.conf | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/wmiistatus.c b/wmiistatus.c index 95cc2ef..6604533 100644 --- a/wmiistatus.c +++ b/wmiistatus.c @@ -102,9 +102,16 @@ static void cleanup_rbar_dir() { static void create_file(const char *name) { char pathbuf[strlen(wmii_path)+256+1]; int fd; + int flags = O_CREAT | O_WRONLY; + struct stat statbuf; (void)snprintf(pathbuf, sizeof(pathbuf), "%s%s", wmii_path, name); - if ((fd = open(pathbuf, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR)) < 0) + + /* Overwrite file's contents if it exists */ + if (stat(pathbuf, &statbuf) >= 0) + flags |= O_TRUNC; + + if ((fd = open(pathbuf, flags, S_IRUSR | S_IWUSR)) < 0) exit(EXIT_FAILURE); if (use_colors) { char *tmp = concat("#888888 ", wmii_normcolors); diff --git a/wmiistatus.conf b/wmiistatus.conf index c483c59..ef0a5cf 100644 --- a/wmiistatus.conf +++ b/wmiistatus.conf @@ -8,3 +8,4 @@ run_watch VPN /var/run/vpnc/pid order run,wlan,eth,battery,load,time normcolors #000000 #333333 color +get_ethspeed -- 2.39.2