Use para_open in exec.c and add error logging.
fade.c: Add proper error return values and error checking.
[AC_MSG_ERROR([function not found, cannot live without it])])
all_errlist_objs="server mp3_afh afh_common vss command net string signal time
[AC_MSG_ERROR([function not found, cannot live without it])])
all_errlist_objs="server mp3_afh afh_common vss command net string signal time
-daemon stat crypt http_send close_on_fork ipc acl afh
+daemon stat crypt http_send close_on_fork ipc acl afh fade
dccp_send fd user_list chunk_queue afs osl aft mood score attribute blob ringbuffer
playlist sha1 rbtree sched audiod grab_client filter_chain wav compress
http_recv dccp_recv recv_common write_common file_write audiod_command
dccp_send fd user_list chunk_queue afs osl aft mood score attribute blob ringbuffer
playlist sha1 rbtree sched audiod grab_client filter_chain wav compress
http_recv dccp_recv recv_common write_common file_write audiod_command
extern const char **para_errlist[];
extern const char **para_errlist[];
+#define FADE_ERRORS \
+ PARA_ERROR(FADE_SYNTAX, "fade syntax error"), \
+
+
#define CLIENT_ERRORS \
PARA_ERROR(TASK_STARTED, "task started"), \
#define CLIENT_ERRORS \
PARA_ERROR(TASK_STARTED, "task started"), \
#define EXEC_ERRORS \
PARA_ERROR(DUP_PIPE, "exec error: can not create pipe"), \
#define EXEC_ERRORS \
PARA_ERROR(DUP_PIPE, "exec error: can not create pipe"), \
- PARA_ERROR(NULL_OPEN, "can not open /dev/null"), \
*/
/** \file exec.c Helper functions for spawning new processes. */
*/
/** \file exec.c Helper functions for spawning new processes. */
#include "para.h"
#include "close_on_fork.h"
#include "error.h"
#include "string.h"
#include "para.h"
#include "close_on_fork.h"
#include "error.h"
#include "string.h"
/**
* Spawn a new process and redirect fd 0, 1, and 2.
/**
* Spawn a new process and redirect fd 0, 1, and 2.
if (fds[2] > 0 && pipe(err) < 0)
goto err_out;
if (!fds[0] || !fds[1] || !fds[2]) {
if (fds[2] > 0 && pipe(err) < 0)
goto err_out;
if (!fds[0] || !fds[1] || !fds[2]) {
- ret = -E_NULL_OPEN;
- null = open("/dev/null", O_RDONLY);
- if (null < 0)
+ ret = para_open("/dev/null", O_RDONLY, 42);
+ if (ret < 0)
- if ((*pid = fork()) < 0)
- exit(EXIT_FAILURE);
+ ret = fork();
+ if (ret < 0) {
+ ret = -ERRNO_TO_PARA_ERROR(errno);
+ goto err_out;
+ }
+ *pid = ret;
if (!(*pid)) { /* child */
close_listed_fds(); /* close unneeded fds */
if (fds[0] >= 0) {
if (!(*pid)) { /* child */
close_listed_fds(); /* close unneeded fds */
if (fds[0] >= 0) {
close(in[1]);
if (null >= 0)
close(null);
close(in[1]);
if (null >= 0)
close(null);
+ PARA_ERROR_LOG("%s\n", para_strerror(-ret));
* Licensed under the GPL v2. For licencing details see COPYING.
*/
* Licensed under the GPL v2. For licencing details see COPYING.
*/
-/** \file fade.c a volume fader and alarm clock */
+/** \file fade.c A volume fader and alarm clock for linux. */
#include <sys/types.h>
#include <dirent.h>
#include <sys/types.h>
#include <dirent.h>
#include <limits.h>
#include <linux/soundcard.h>
#include "string.h"
#include <limits.h>
#include <linux/soundcard.h>
#include "string.h"
struct fade_args_info conf;
void para_log(__a_unused int ll, const char *fmt,...)
struct fade_args_info conf;
void para_log(__a_unused int ll, const char *fmt,...)
*/
static int open_mixer(void)
{
*/
static int open_mixer(void)
{
- return open(conf.mixer_device_arg, O_RDWR, 0);
+ return para_open(conf.mixer_device_arg, O_RDWR, 42);
int volume;
if (ioctl(mixer_fd, MIXER_READ(SOUND_MIXER_VOLUME), &volume) < 0)
int volume;
if (ioctl(mixer_fd, MIXER_READ(SOUND_MIXER_VOLUME), &volume) < 0)
+ return -ERRNO_TO_PARA_ERROR(errno);
/* take the mean value of left and right volume */
return (volume % 256 + (volume >> 8)) / 2;
}
/* take the mean value of left and right volume */
return (volume % 256 + (volume >> 8)) / 2;
}
mixer_fd = open_mixer();
if (mixer_fd < 0)
mixer_fd = open_mixer();
if (mixer_fd < 0)
volume = do_get_vol(mixer_fd);
close(mixer_fd);
return volume;
volume = do_get_vol(mixer_fd);
close(mixer_fd);
return volume;
int tmp = (volume << 8) + volume;
if (ioctl(mixer_fd, MIXER_WRITE(SOUND_MIXER_VOLUME), &tmp) < 0)
int tmp = (volume << 8) + volume;
if (ioctl(mixer_fd, MIXER_WRITE(SOUND_MIXER_VOLUME), &tmp) < 0)
+ return -ERRNO_TO_PARA_ERROR(errno);
* Open mixer, get volume, fade to new_vol in secs seconds and
* close mixer
*/
* Open mixer, get volume, fade to new_vol in secs seconds and
* close mixer
*/
-static void fade(int new_vol, int fade_time)
+static int fade(int new_vol, int fade_time)
- int vol, mixer_fd, diff, incr;
+ int vol, mixer_fd, diff, incr, ret;
unsigned secs;
struct timespec ts;
unsigned long long tmp, tmp2; /* Careful with that axe, Eugene! */
if (fade_time <= 0)
unsigned secs;
struct timespec ts;
unsigned long long tmp, tmp2; /* Careful with that axe, Eugene! */
if (fade_time <= 0)
secs = fade_time;
PARA_NOTICE_LOG("fading to %d in %d seconds\n", new_vol, secs);
secs = fade_time;
PARA_NOTICE_LOG("fading to %d in %d seconds\n", new_vol, secs);
- mixer_fd = open_mixer();
- if (mixer_fd < 0)
- return;
- vol = do_get_vol(mixer_fd);
- if (vol < 0)
+ ret = open_mixer();
+ if (ret < 0)
+ return ret;
+ mixer_fd = ret;
+ ret = do_get_vol(mixer_fd);
+ if (ret < 0)
diff = new_vol - vol;
if (!diff) {
sleep(secs);
diff = new_vol - vol;
if (!diff) {
sleep(secs);
ts.tv_sec = tmp / 1000; /* really nec ?*/
//printf("ts.tv_sec: %i\n", ts.tv_nsec);
vol += incr;
ts.tv_sec = tmp / 1000; /* really nec ?*/
//printf("ts.tv_sec: %i\n", ts.tv_nsec);
vol += incr;
- if (do_set_vol(mixer_fd, vol) < 0)
+ ret = do_set_vol(mixer_fd, vol);
+ if (ret < 0)
goto out;
//printf("vol = %i\n", vol);
nanosleep(&ts, NULL);
}
out:
close(mixer_fd);
goto out;
//printf("vol = %i\n", vol);
nanosleep(&ts, NULL);
}
out:
close(mixer_fd);
}
static void client_cmd(const char *cmd)
}
static void client_cmd(const char *cmd)
PARA_INFO_LOG("%s\n", cmdline);
ret = para_exec_cmdline_pid(&pid, cmdline, fds);
free(cmdline);
PARA_INFO_LOG("%s\n", cmdline);
ret = para_exec_cmdline_pid(&pid, cmdline, fds);
free(cmdline);
+ if (ret < 0) {
+ PARA_EMERG_LOG("%s\n", para_strerror(-ret));
do
ret = wait(NULL);
while (ret != -1 && errno != ECHILD);
do
ret = wait(NULL);
while (ret != -1 && errno != ECHILD);
-static void sweet_dreams(void)
+static int sweet_dreams(void)
{
time_t t1, wake_time_epoch;
unsigned int delay;
struct tm *tm;
{
time_t t1, wake_time_epoch;
unsigned int delay;
struct tm *tm;
- int min = conf.wake_min_arg;
+ int ret, min = conf.wake_min_arg;
char *fa_mode = conf.fa_mode_arg;
char *wake_mode = conf.wake_mode_arg;
char *sleep_mode = conf.sleep_mode_arg;
char *fa_mode = conf.fa_mode_arg;
char *wake_mode = conf.wake_mode_arg;
char *sleep_mode = conf.sleep_mode_arg;
sleep(1);
if (sf) {
PARA_INFO_LOG("initial volume: %d\n", iv);
sleep(1);
if (sf) {
PARA_INFO_LOG("initial volume: %d\n", iv);
+ ret = set_vol(iv);
+ if (ret < 0)
+ return ret;
change_afs_mode_and_play(fa_mode);
change_afs_mode_and_play(fa_mode);
- fade(sv, sf);
- } else
- set_vol(sf);
+ ret = fade(sv, sf);
+ if (ret < 0)
+ return ret;
+ } else {
+ ret = set_vol(sf);
+ if (ret < 0)
+ return ret;
+ }
change_afs_mode_and_play(sleep_mode);
if (!wf)
change_afs_mode_and_play(sleep_mode);
if (!wf)
for (;;) {
time(&t1);
if (wake_time_epoch <= t1 + wf)
for (;;) {
time(&t1);
if (wake_time_epoch <= t1 + wf)
sleep(delay);
}
change_afs_mode_and_play(wake_mode);
sleep(delay);
}
change_afs_mode_and_play(wake_mode);
PARA_INFO_LOG("fade complete, returning\n");
PARA_INFO_LOG("fade complete, returning\n");
-static void snooze(void)
unsigned sleep_time;
if (conf.snooze_time_arg <= 0)
unsigned sleep_time;
if (conf.snooze_time_arg <= 0)
sleep_time = conf.snooze_time_arg;
if (get_vol() < conf.snooze_out_vol_arg)
sleep_time = conf.snooze_time_arg;
if (get_vol() < conf.snooze_out_vol_arg)
- set_vol(conf.snooze_out_vol_arg);
+ ret = set_vol(conf.snooze_out_vol_arg);
- fade(conf.snooze_out_vol_arg, conf.snooze_out_fade_arg);
+ ret = fade(conf.snooze_out_vol_arg, conf.snooze_out_fade_arg);
+ if (ret < 0)
+ return ret;
client_cmd("pause");
PARA_NOTICE_LOG("%d seconds snooze time...\n", conf.snooze_time_arg);
sleep(sleep_time);
client_cmd("play");
client_cmd("pause");
PARA_NOTICE_LOG("%d seconds snooze time...\n", conf.snooze_time_arg);
sleep(sleep_time);
client_cmd("play");
- fade(conf.snooze_in_vol_arg, conf.snooze_in_fade_arg);
+ return fade(conf.snooze_in_vol_arg, conf.snooze_in_fade_arg);
}
static int configfile_exists(void)
}
static int configfile_exists(void)
return file_exists(conf.config_file_arg);
}
return file_exists(conf.config_file_arg);
}
int main(int argc, char *argv[])
{
int ret;
int main(int argc, char *argv[])
{
int ret;
fade_cmdline_parser_config_file(conf.config_file_arg,
&conf, ¶ms);
}
fade_cmdline_parser_config_file(conf.config_file_arg,
&conf, ¶ms);
}
- ret = open_mixer();
- if (ret < 0) {
- PARA_EMERG_LOG("can not open mixer device %s.",
- conf.mixer_device_arg);
- exit(EXIT_FAILURE);
- }
- close(ret);
- ret = 0;
-// setlinebuf(stdout);
if (!strcmp(conf.mode_arg, "sleep")) {
if (!strcmp(conf.mode_arg, "sleep")) {
goto out;
}
if (!strcmp(conf.mode_arg, "fade")) {
goto out;
}
if (!strcmp(conf.mode_arg, "fade")) {
- fade(conf.fade_vol_arg, conf.fade_time_arg);
+ ret = fade(conf.fade_vol_arg, conf.fade_time_arg);
goto out;
}
if (!strcmp(conf.mode_arg, "snooze")) {
goto out;
}
if (!strcmp(conf.mode_arg, "snooze")) {
+ if (ret < 0)
+ PARA_EMERG_LOG("%s\n", para_strerror(-ret));
return ret < 0? EXIT_FAILURE : EXIT_SUCCESS;
}
return ret < 0? EXIT_FAILURE : EXIT_SUCCESS;
}