commit - 91d449e4dd54dcb76dde2962e292de425072bc2e
commit + a55e0e43a86b71548e22a041b2441ed4d485db7b
blob - 8bf34584a10a16109475d9e906cd131a37ed59bc
blob + fbd7a7db49aa24ed39154b9e5d39d526da1e848c
--- include/statbar.h
+++ include/statbar.h
extern void close_display(void);
/* FS */
-extern bool weather_loc_valid;
-
extern void read_config(void);
extern int open_command_interface(void);
extern int open_output(void);
extern void get_fanspeed(void);
-/* Weather */
-extern char weather_string[48];
-
-extern void get_weather(int fd);
-extern void read_weather(int fd);
-extern char **get_weather_location_ptr(void);
-extern void close_weather(void);
-
/* Mail */
extern char mail_string[7];
blob - 4952920f95c0803025a7b58870ca6d3d1e261a3f
blob + a539d6cd091520c896d42d7b677c2a7435711c2f
--- modules/Makefile
+++ modules/Makefile
LIB= statbar_modules
-SRCS= clock.c battery.c volume.c cputemp.c fanspeed.c weather.c mail.c network.c
+SRCS= clock.c battery.c volume.c cputemp.c fanspeed.c mail.c network.c
MAN=
CFLAGS += -I../include -I/usr/local/include
blob - 208a88ac24abd104329c516b6de60d521864ff5f (mode 644)
blob + /dev/null
--- modules/weather.c
+++ /dev/null
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <fcntl.h>
-#include <unistd.h>
-
-#include "statbar.h"
-
-#define MAX_RETRY_ATTEMPTS 5
-
-char weather_string[48] = "...";
-
-static char *weather_location;
-
-char **
-get_weather_location_ptr(void)
-{
- return &weather_location;
-}
-
-void
-get_weather(int fd)
-{
- pid_t pid = fork();
- char *argv[] = { "/usr/local/bin/weatherbar", weather_location, NULL };
-
- if (pid != 0)
- {
- if (pid < 0) perror("fork");
-
- return;
- }
- (void)dup2(fd, STDOUT_FILENO);
- if (execv("/usr/local/bin/weatherbar", argv) < 0)
- {
- perror("execv");
- _exit(1);
- }
-}
-
-void
-read_weather(int fd)
-{
- ssize_t n = read(fd, weather_string, sizeof(weather_string) - 1);
- char *lnbrk;
- char garbage[1024];
- int flags = fcntl(fd, F_GETFL, 0);
-
- if (n < 0)
- {
- perror("read");
-
- return;
- }
- weather_string[n] = '\0';
- lnbrk = strchr(weather_string, '\n');
- if (lnbrk) *lnbrk = '\0';
- (void)fcntl(fd, F_SETFL, flags | O_NONBLOCK);
- while (read(fd, garbage, sizeof(garbage)) > 0);
- (void)fcntl(fd, F_SETFL, flags);
-}
-
-void
-close_weather(void)
-{
- free(weather_location);
-}
-
blob - 4f58a5ada29f8649fdd13eb38c8510099cb3298a
blob + cde058e7605074a5c1d529255557f1e196ff03b3
--- src/fs.c
+++ src/fs.c
nline = strchr(delim, '\n');
if (nline != NULL) *nline = '\0';
- if (strncmp(line, "weather location", strlen("weather location")) == 0)
- {
- weather_location = get_weather_location_ptr();
- if (weather_loc_valid && *weather_location != NULL) close_weather();
- delim++;
- while (*delim == ' ') delim++;
- *weather_location = strdup(delim);
- if (*weather_location == NULL)
- perror("strdup");
- else
- weather_loc_valid = true;
-
- continue;
- }
if (strncmp(line, "inbox directory", strlen("inbox directory")) == 0)
{
mail_ptr = get_append_mail_path_ptr();
uid_t uid;
struct passwd *pw;
- (void)puts("Creating FIFO...");
-
uid = getuid();
pw = getpwuid(uid);
return -1;
}
+ (void)printf("Creating FIFO %s\n", *path);
if (mkfifo(*path, 0600) != 0 && errno != EEXIST)
{
perror("mkfifo");
blob - 01276ea7f9874a7eb8c8dbbdbb0c5883d5e4ca0b
blob + 990ebf176a7a2f3d80a0cba669c559a1de3d6f7c
--- src/main.c
+++ src/main.c
#include "statbar.h"
-#define NFDS 5
+#define NFDS 4
enum clocks_e
{
CLOCK_CLOCK,
CPUTEMP_CLOCK,
FANSPEED_CLOCK,
- WEATHER_CLOCK,
CLOCKS_COUNT
};
static volatile sig_atomic_t should_quit = 0;
-static int reload_weather = 0;
static int reload_mail = 0;
static int reload_battery = 0;
-bool weather_loc_valid = false;
-
void
sig_handler(int sig)
{
int batt_fd;
int vol_fd;
int network_fd;
- int weather_pipe[2];
pid_t batt_pid;
pid_t vol_pid;
pid_t network_pid;
struct timespec battery_interval = { .tv_sec = 10 };
struct timespec cputemp_interval = { .tv_sec = 2 };
struct timespec fanspeed_interval = { .tv_sec = 3 };
- struct timespec weather_interval = { .tv_sec = 1800 };
struct pollfd pfd[NFDS];
struct pollfd *cmd_pfd = &pfd[0];
struct pollfd *batt_pfd = &pfd[1];
struct pollfd *vol_pfd = &pfd[2];
struct pollfd *network_pfd = &pfd[3];
- struct pollfd *weather_pfd = &pfd[4];
char battery_string[BATTERY_STRING_SIZE];
char volume_string[VOLUME_STRING_SIZE];
char network_string[NETWORK_STRING_SIZE];
ssize_t n;
(void)setvbuf(stdout, NULL, _IOLBF, 0);
+ (void)puts("Welcome to statbar");
output_fd = open_output();
- printf("Got fd %d\n", output_fd);
if (output_fd == -1)
{
(void)puts("Failed to open output FIFO");
}
install_signal_handlers();
- (void)puts("Welcome to statbar");
-
/* Init components */
(void)puts("Reading config...");
read_config();
normalize_clock_interval(&now, &clocks[CLOCK_CLOCK]);
timespecadd(&now, &cputemp_interval, &clocks[CPUTEMP_CLOCK]);
timespecadd(&now, &fanspeed_interval, &clocks[FANSPEED_CLOCK]);
- timespecadd(&now, &weather_interval, &clocks[WEATHER_CLOCK]);
get_clock();
batt_pid = start_privileged_battery_process(&batt_fd, &battery_interval);
get_cputemp();
get_fanspeed();
- if (pipe(weather_pipe) != 0)
- {
- perror("pipe");
- weather_loc_valid = false;
- }
-
cmd_pfd->fd = open_command_interface();
cmd_pfd->events = POLLIN;
if (batt_pid > 0)
network_pfd->fd = network_fd;
network_pfd->events = POLLIN;
}
- if (weather_loc_valid)
- {
- weather_pfd->fd = weather_pipe[0];
- weather_pfd->events = POLLIN;
- get_weather(weather_pipe[1]);
- }
get_mail();
- if (pledge("stdio rpath cpath proc exec", NULL) == -1)
+ if (pledge("stdio rpath cpath proc", NULL) == -1)
{
perror("pledge");
(void)printf("Got command 0x%02x: ", cmd);
switch (cmd)
{
- case 0x02:
- (void)puts("reloading weather");
- reload_weather = 1;
- break;
case 0x03:
(void)puts("reloading mail");
reload_mail = 1;
n = read(network_pfd->fd, network_string, NETWORK_STRING_SIZE);
if (n > 0) network_string[n] = '\0';
}
- if (weather_pfd && (weather_pfd->revents & POLLIN))
- read_weather(weather_pfd->fd);
dirty = true;
}
timespecadd(&clocks[FANSPEED_CLOCK], &fanspeed_interval, &clocks[FANSPEED_CLOCK]);
}
- /* Weather */
- if (weather_loc_valid && weather_pfd && (reload_weather == 1 || timespeccmp(&now, &clocks[WEATHER_CLOCK], >=)))
- {
- reload_weather = 0;
- get_weather(weather_pipe[1]);
- while (timespeccmp(&now, &clocks[WEATHER_CLOCK], >=))
- timespecadd(&clocks[WEATHER_CLOCK], &weather_interval, &clocks[WEATHER_CLOCK]);
- }
-
if (dirty)
{
- (void)dprintf(output_fd, "%s | %s | %s | %s | %s | %s | %s%s\n",
+ (void)dprintf(output_fd, "%s | %s | %s | %s | %s | %s%s\n",
clock_string,
battery_string,
volume_string,
cputemp_string,
fanspeed_string,
- weather_string,
network_string,
mail_string);
dirty = false;
if (batt_pid > 0) (void)kill(batt_pid, SIGTERM);
if (vol_pid > 0) (void)kill(vol_pid, SIGTERM);
if (network_pid > 0) (void)kill(network_pid, SIGTERM);
- if (weather_loc_valid) close_weather();
close_mail();
- if (weather_pfd)
- {
- weather_pfd = NULL;
- (void)close(weather_pipe[0]);
- (void)close(weather_pipe[1]);
- }
close_fifos();
return 0;
blob - 29fb3abfe8be343c3793cab793729d60c54f1e4d
blob + 3fc672918f869da97a24e6eabb090b7717276205
--- statbarctl.sh
+++ statbarctl.sh
echo "\nstatbarctl is used to control aspects of a running statbar instance"
echo "statbar must be running for this program to be useful"
echo "\nUsage:"
- echo "\tstatbarctl reload-weather: refresh the weather module"
echo "\tstatbarctl reload-mail: refresh the mail module"
echo "\tstatbarctl reload-battery: refresh the battery module"
echo "\tstatbarctl help: show this message"
fi
case "$1" in
- reload-weather) CMDBYTE="\x02" ;;
reload-mail) CMDBYTE="\x03" ;;
reload-battery) CMDBYTE="\x04" ;;
help)
blob - 19609385b5d65a8c953442b9ad7b2c89c44acc95 (mode 755)
blob + /dev/null
--- weatherbar.sh
+++ /dev/null
-#!/bin/sh
-
-if [ -z "$1" ]; then
- echo "Must specify location!" > /dev/stderr
-
- exit 1;
-fi
-
-ftp -Vo - "https://wttr.in/${1}?u&format=1" 2> /dev/null
-