fixed initialization issues

We were not returning exit codes properly if we were unable to open the
softsynth or if the daemon was already running.
This commit is contained in:
William Hubbs 2009-05-30 12:37:58 -05:00
commit d7dd0f919d
3 changed files with 24 additions and 18 deletions

View file

@ -105,6 +105,16 @@ int main(int argc, char **argv)
return 1;
}
/* open the softsynth. */
if (! open_softsynth()) {
perror("Unable to open the softsynth device");
return 3;
}
/* register signal handler */
signal(SIGINT, espeakup_sighandler);
signal(SIGTERM, espeakup_sighandler);
if (!debug) {
/* become a daemon */
daemon(0, 1);
@ -116,15 +126,6 @@ int main(int argc, char **argv)
}
}
/* Spawn our queue-processing thread. */
int err = pthread_create(&queue_thread_id, NULL, &queue_runner, &s);
if (err != 0) {
return 4;
}
/* open the softsynth. */
open_softsynth();
/* initialize espeak */
espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 0, NULL, 0);
@ -140,9 +141,11 @@ int main(int argc, char **argv)
set_volume(&s, defaultVolume, ADJ_SET);
espeak_SetParameter(espeakCAPITALS, 0, 0);
/* register signal handler */
signal(SIGINT, espeakup_sighandler);
signal(SIGTERM, espeakup_sighandler);
/* Spawn our queue-processing thread. */
int err = pthread_create(&queue_thread_id, NULL, &queue_runner, &s);
if (err != 0) {
return 4;
}
/* run the main loop */
main_loop(&s);

View file

@ -74,7 +74,7 @@ extern espeak_ERROR set_volume(struct synth_t *s, int vol,
enum adjust_t adj);
extern espeak_ERROR stop_speech(void);
extern espeak_ERROR speak_text(struct synth_t *s);
extern void open_softsynth(void);
extern int open_softsynth(void);
extern void close_softsynth(void);
extern void main_loop(struct synth_t *s);
extern void * queue_runner(void *arg);

View file

@ -125,13 +125,16 @@ static void process_buffer(struct synth_t *s, char *buf, ssize_t length)
}
}
void open_softsynth(void)
int open_softsynth(void)
{
int rc;
softFD = open("/dev/softsynth", O_RDWR | O_NONBLOCK);
if (softFD < 0) {
perror("Unable to open the softsynth device");
exit(3);
}
if (softFD < 0)
rc = 0;
else
rc = 1;
return rc;
}
void close_softsynth(void)