Fix warnings from gcc 4.6.3

This commit is contained in:
Andrew Bettison 2013-03-18 16:39:08 +10:30
parent 7d312f51fb
commit 300ec986f1
8 changed files with 117 additions and 57 deletions

View File

@ -769,13 +769,17 @@ int app_server_start(const struct cli_parsed *parsed, void *context)
close_logging();
int fd;
if ((fd = open("/dev/null", O_RDWR, 0)) == -1)
_exit(WHY_perror("open"));
_exit(WHY_perror("open(\"/dev/null\")"));
if (setsid() == -1)
_exit(WHY_perror("setsid"));
(void)chdir(dir);
(void)dup2(fd, 0);
(void)dup2(fd, 1);
(void)dup2(fd, 2);
if (chdir(dir) == -1)
_exit(WHYF_perror("chdir(%s)", alloca_str_toprint(dir)));
if (dup2(fd, 0) == -1)
_exit(WHYF_perror("dup2(%d,0)", fd));
if (dup2(fd, 1) == -1)
_exit(WHYF_perror("dup2(%d,1)", fd));
if (dup2(fd, 2) == -1)
_exit(WHYF_perror("dup2(%d,2)", fd));
if (fd > 2)
(void)close(fd);
/* The execpath option is provided so that a JNI call to "start" can be made which

28
lsif.c
View File

@ -76,25 +76,29 @@ int scrapeProcNetRoute()
if (config.debug.overlayinterfaces) DEBUG("called");
FILE *f=fopen("/proc/net/route","r");
if (!f) return WHY_perror("fopen(\"/proc/net/route\")");
if (!f)
return WHY_perror("fopen(\"/proc/net/route\")");
char line[1024],name[1024],dest[1024],mask[1024];
/* skip header line */
line[0]=0; fgets(line,1024,f);
line[0] = '\0';
if (fgets(line,1024,f) == NULL)
return WHYF_perror("fgets(%p,1024,\"/proc/net/route\")", line);
line[0]=0; fgets(line,1024,f);
line[0] = '\0';
if (fgets(line,1024,f) == NULL)
return WHYF_perror("fgets(%p,1024,\"/proc/net/route\")", line);
while(line[0]) {
int r;
if ((r=sscanf(line,"%s %s %*s %*s %*s %*s %*s %s",name,dest,mask))==3)
{
struct in_addr addr = {.s_addr=strtol(dest,NULL,16)};
struct in_addr netmask = {.s_addr=strtol(mask,NULL,16)};
overlay_interface_register(name,addr,netmask);
}
line[0]=0; fgets(line,1024,f);
if ((r=sscanf(line,"%s %s %*s %*s %*s %*s %*s %s",name,dest,mask))==3) {
struct in_addr addr = {.s_addr=strtol(dest,NULL,16)};
struct in_addr netmask = {.s_addr=strtol(mask,NULL,16)};
overlay_interface_register(name,addr,netmask);
}
line[0] = '\0';
if (fgets(line,1024,f) == NULL)
return WHYF_perror("fgets(%p,1024,\"/proc/net/route\")", line);
}
fclose(f);
return 0;

View File

@ -67,10 +67,22 @@ int app_monitor_cli(const struct cli_parsed *parsed, void *context)
if (fds[0].revents & POLLIN){
char buff[256];
int bytes = read(STDIN_FILENO, buff, sizeof(buff));
set_block(monitor_client_fd);
write(monitor_client_fd, buff, bytes);
set_nonblock(monitor_client_fd);
ssize_t bytes = read(STDIN_FILENO, buff, sizeof buff);
if (bytes == -1)
WHYF_perror("read(%d,%p,%ld)", STDIN_FILENO, buff, (long)sizeof buff);
else {
set_block(monitor_client_fd);
size_t to_write = bytes;
size_t written = 0;
while (written < to_write) {
ssize_t n = write(monitor_client_fd, buff + written, to_write - written);
if (n == -1)
WHYF_perror("write(%d,%p,%ld)", monitor_client_fd, buff, (long)bytes);
else
written += n;
}
set_nonblock(monitor_client_fd);
}
}
if (fds[1].revents & POLLIN){

View File

@ -542,7 +542,10 @@ static int monitor_call_dtmf(const struct cli_parsed *parsed, void *context)
return 0;
}
struct cli_schema monitor_options[]={
static int monitor_help(const struct cli_parsed *parsed, void *context);
struct cli_schema monitor_commands[] = {
{monitor_help,{"help",NULL},0,""},
{monitor_set,{"monitor","vomp","<codec>","...",NULL},0,""},
{monitor_set,{"monitor","<type>",NULL},0,""},
{monitor_clear,{"ignore","<type>",NULL},0,""},
@ -562,12 +565,32 @@ int monitor_process_command(struct monitor_context *c)
int argc = parse_argv(c->line, ' ', argv, 16);
struct cli_parsed parsed;
int res = cli_parse(argc, (const char *const*)argv, monitor_options, &parsed);
int res = cli_parse(argc, (const char *const*)argv, monitor_commands, &parsed);
if (res == -1 || cli_invoke(&parsed, c))
return monitor_write_error(c, "Invalid command");
return 0;
}
static int monitor_help(const struct cli_parsed *parsed, void *context)
{
struct monitor_context *c=context;
strbuf b = strbuf_alloca(16384);
strbuf_puts(b, "\nINFO:Usage\n");
unsigned cmd;
for (cmd = 0; monitor_commands[cmd].function; ++cmd) {
unsigned opt;
const char *word;
for (opt = 0; (word = monitor_commands[cmd].words[opt]); ++opt) {
if (word[0] == '\\')
++word;
strbuf_sprintf(b, " %s", word);
}
strbuf_puts(b, "\n");
}
(void)write_all(c->alarm.poll.fd, strbuf_str(b), strbuf_len(b));
return 0;
}
int monitor_announce_bundle(rhizome_manifest *m)
{
int i;

View File

@ -39,11 +39,11 @@ int overlay_packetradio_setup_port(overlay_interface *interface)
tcsetattr(interface->alarm.poll.fd, TCSANOW, &t);
// Ask radio to report RSSI
write(interface->alarm.poll.fd,"\r",1);
(void)write_all(interface->alarm.poll.fd,"\r",1);
usleep(1200000);
write(interface->alarm.poll.fd,"+++",3);
(void)write_all(interface->alarm.poll.fd,"+++",3);
usleep(1200000);
write(interface->alarm.poll.fd,"\rAT&T\rAT&T=RSSI\rATO\r",20);
(void)write_all(interface->alarm.poll.fd,"\rAT&T\rAT&T=RSSI\rATO\r",20);
if (config.debug.packetradio) {
DEBUGF("Enabled RSSI reporting for RFD900 radios");
DEBUGF("Sent ATO to make sure we are in on-line mode");
@ -55,7 +55,7 @@ int overlay_packetradio_setup_port(overlay_interface *interface)
int i;
for (i=0;i<sizeof buff;i++)
buff[i]=i;
write(interface->alarm.poll.fd,buff,sizeof buff);
(void)write_all(interface->alarm.poll.fd,buff,sizeof buff);
}
set_nonblock(interface->alarm.poll.fd);

View File

@ -378,10 +378,7 @@ int rhizome_direct_process_mime_line(rhizome_http_request *r,char *buffer,int co
r->field_file=fopen(filename,"w");
if (!r->field_file) {
WHYF_perror("fopen(%s, \"w\")", alloca_str_toprint(filename));
rhizome_direct_clear_temporary_files(r);
rhizome_server_simple_http_response
(r, 500, "<html><h1>Sorry, couldn't complete your request, reasonable as it was. Perhaps try again later.</h1></html>\r\n");
return -1;
goto scram;
}
r->source_flags=RD_MIME_STATE_BODY;
} else {
@ -414,15 +411,23 @@ int rhizome_direct_process_mime_line(rhizome_http_request *r,char *buffer,int co
case RD_MIME_STATE_BODY:
if (boundaryLine) {
r->source_flags=RD_MIME_STATE_PARTHEADERS;
/* We will have written an extra CRLF to the end of the file,
so prune that off. */
fflush(r->field_file);
int fd=fileno(r->field_file);
off_t correct_size=ftell(r->field_file)-2;
ftruncate(fd,correct_size);
fclose(r->field_file);
r->field_file=NULL;
/* We will have written an extra CRLF to the end of the file, so prune that off. */
if (fflush(r->field_file) == EOF) {
WHYF_perror("fflush()");
goto scram;
}
int fd = fileno(r->field_file);
off_t correct_size = ftell(r->field_file) - 2;
if (ftruncate(fd,correct_size) == -1) {
WHYF_perror("ftruncate()");
goto scram;
}
if (fclose(r->field_file) == EOF) {
WHYF_perror("fclose()");
r->field_file = NULL;
goto scram;
}
r->field_file = NULL;
}
else {
int written=fwrite(r->request,count,1,r->field_file);
@ -443,6 +448,16 @@ int rhizome_direct_process_mime_line(rhizome_http_request *r,char *buffer,int co
return rhizome_direct_form_received(r);
}
return 0;
scram:
if (r->field_file) {
if (fclose(r->field_file) == EOF)
WARNF_perror("fclose()");
}
rhizome_direct_clear_temporary_files(r);
rhizome_server_simple_http_response(r, 500,
"<html><h1>Sorry, couldn't complete your request, reasonable as it was. Perhaps try again later.</h1></html>\r\n");
return -1;
}
int rhizome_direct_process_post_multipart_bytes(rhizome_http_request *r,const char *bytes,int count)

View File

@ -65,9 +65,8 @@ int server_pid()
FILE *f = NULL;
if ((f = fopen(filename, "r"))) {
char buf[20];
fgets(buf, sizeof buf, f);
int pid = (fgets(buf, sizeof buf, f) != NULL) ? atoi(buf) : -1;
fclose(f);
int pid = atoi(buf);
if (pid > 0 && kill(pid, 0) != -1)
return pid;
INFOF("Unlinking stale pidfile %s", filename);

View File

@ -56,6 +56,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#endif
#include "os.h"
#include "log.h"
#include <fcntl.h>
#include <stdlib.h>
#include <time.h>
@ -63,22 +64,24 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
void
srandomdev(void)
{
struct timeval tv;
unsigned int seed;
unsigned int seed;
int seeded = 0;
#ifndef WIN32
FILE *fd;
fd = fopen("/dev/urandom", "r");
if (fd >= 0) {
fread(&seed, sizeof seed, 1, fd);
fclose(fd);
} else
FILE *fd;
fd = fopen("/dev/urandom", "r");
if (fd >= 0) {
if (fread(&seed, sizeof seed, 1, fd) != 1)
WARNF("fread(\"/dev/urandom\") failed -- falling back to gettimeofday()");
else
seeded = 1;
fclose(fd);
}
#endif
{
gettimeofday(&tv, NULL);
seed = (getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec;
}
srandom(seed);
if (!seeded) {
struct timeval tv;
gettimeofday(&tv, NULL);
seed = (getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec;
}
srandom(seed);
}
#endif