comparison mcabber/src/fifo.c @ 1572:8c0237c8c186

Export the FIFO pipe name as an environment variable (Lukas Kuklinek)
author Mikael Berthe <mikael@lilotux.net>
date Sat, 11 Apr 2009 12:30:51 +0200
parents eefa0ae248d8
children a087125d8fc8
comparison
equal deleted inserted replaced
1571:481b60da99c9 1572:8c0237c8c186
37 #include "hbuf.h" // For HBB_BLOCKSIZE 37 #include "hbuf.h" // For HBB_BLOCKSIZE
38 38
39 static FILE *sfd; 39 static FILE *sfd;
40 static char *fifo_name; 40 static char *fifo_name;
41 41
42 static const char *FIFO_ENV_NAME = "MCABBER_FIFO";
42 43
43 // fifo_init(fifo_path) 44 // fifo_init(fifo_path)
44 // Create and open the FIFO file. 45 // Create and open the FIFO file.
45 // If fifo_path is NULL, reopen the current pipe. 46 // If fifo_path is NULL, reopen the current pipe.
46 // Return 0 (success) or -1 (failure). 47 // Return 0 (success) or -1 (failure).
91 fifo_init_open: 92 fifo_init_open:
92 fd = open(fifo_name, O_RDONLY | O_NONBLOCK); 93 fd = open(fifo_name, O_RDONLY | O_NONBLOCK);
93 if (!fd) 94 if (!fd)
94 return -1; 95 return -1;
95 96
97 setenv(FIFO_ENV_NAME, fifo_name, 1);
98
96 sfd = fdopen(fd, "r"); 99 sfd = fdopen(fd, "r");
97 if (fifo_path) 100 if (fifo_path)
98 scr_LogPrint(LPRINT_LOGNORM, "FIFO initialized (%s)", fifo_name); 101 scr_LogPrint(LPRINT_LOGNORM, "FIFO initialized (%s)", fifo_name);
99 return 0; 102 return 0;
100 } 103 }
101 104
102 // fifo_deinit() 105 // fifo_deinit()
103 // Close the current FIFO pipe and delete it. 106 // Close the current FIFO pipe and delete it.
104 void fifo_deinit(void) 107 void fifo_deinit(void)
105 { 108 {
109 unsetenv(FIFO_ENV_NAME);
106 if (sfd) { 110 if (sfd) {
107 fclose(sfd); 111 fclose(sfd);
108 sfd = NULL; 112 sfd = NULL;
109 } 113 }
110 if (fifo_name) { 114 if (fifo_name) {