mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-20 05:37:57 +00:00
Fix warnings from gcc 4.6.3
This commit is contained in:
parent
7d312f51fb
commit
300ec986f1
@ -769,13 +769,17 @@ int app_server_start(const struct cli_parsed *parsed, void *context)
|
|||||||
close_logging();
|
close_logging();
|
||||||
int fd;
|
int fd;
|
||||||
if ((fd = open("/dev/null", O_RDWR, 0)) == -1)
|
if ((fd = open("/dev/null", O_RDWR, 0)) == -1)
|
||||||
_exit(WHY_perror("open"));
|
_exit(WHY_perror("open(\"/dev/null\")"));
|
||||||
if (setsid() == -1)
|
if (setsid() == -1)
|
||||||
_exit(WHY_perror("setsid"));
|
_exit(WHY_perror("setsid"));
|
||||||
(void)chdir(dir);
|
if (chdir(dir) == -1)
|
||||||
(void)dup2(fd, 0);
|
_exit(WHYF_perror("chdir(%s)", alloca_str_toprint(dir)));
|
||||||
(void)dup2(fd, 1);
|
if (dup2(fd, 0) == -1)
|
||||||
(void)dup2(fd, 2);
|
_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)
|
if (fd > 2)
|
||||||
(void)close(fd);
|
(void)close(fd);
|
||||||
/* The execpath option is provided so that a JNI call to "start" can be made which
|
/* The execpath option is provided so that a JNI call to "start" can be made which
|
||||||
|
28
lsif.c
28
lsif.c
@ -76,25 +76,29 @@ int scrapeProcNetRoute()
|
|||||||
if (config.debug.overlayinterfaces) DEBUG("called");
|
if (config.debug.overlayinterfaces) DEBUG("called");
|
||||||
|
|
||||||
FILE *f=fopen("/proc/net/route","r");
|
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];
|
char line[1024],name[1024],dest[1024],mask[1024];
|
||||||
|
|
||||||
/* skip header line */
|
/* 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]) {
|
while(line[0]) {
|
||||||
int r;
|
int r;
|
||||||
if ((r=sscanf(line,"%s %s %*s %*s %*s %*s %*s %s",name,dest,mask))==3)
|
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 addr = {.s_addr=strtol(dest,NULL,16)};
|
struct in_addr netmask = {.s_addr=strtol(mask,NULL,16)};
|
||||||
struct in_addr netmask = {.s_addr=strtol(mask,NULL,16)};
|
overlay_interface_register(name,addr,netmask);
|
||||||
|
}
|
||||||
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);
|
||||||
line[0]=0; fgets(line,1024,f);
|
|
||||||
}
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -67,10 +67,22 @@ int app_monitor_cli(const struct cli_parsed *parsed, void *context)
|
|||||||
|
|
||||||
if (fds[0].revents & POLLIN){
|
if (fds[0].revents & POLLIN){
|
||||||
char buff[256];
|
char buff[256];
|
||||||
int bytes = read(STDIN_FILENO, buff, sizeof(buff));
|
ssize_t bytes = read(STDIN_FILENO, buff, sizeof buff);
|
||||||
set_block(monitor_client_fd);
|
if (bytes == -1)
|
||||||
write(monitor_client_fd, buff, bytes);
|
WHYF_perror("read(%d,%p,%ld)", STDIN_FILENO, buff, (long)sizeof buff);
|
||||||
set_nonblock(monitor_client_fd);
|
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){
|
if (fds[1].revents & POLLIN){
|
||||||
|
27
monitor.c
27
monitor.c
@ -542,7 +542,10 @@ static int monitor_call_dtmf(const struct cli_parsed *parsed, void *context)
|
|||||||
return 0;
|
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","vomp","<codec>","...",NULL},0,""},
|
||||||
{monitor_set,{"monitor","<type>",NULL},0,""},
|
{monitor_set,{"monitor","<type>",NULL},0,""},
|
||||||
{monitor_clear,{"ignore","<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);
|
int argc = parse_argv(c->line, ' ', argv, 16);
|
||||||
|
|
||||||
struct cli_parsed parsed;
|
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))
|
if (res == -1 || cli_invoke(&parsed, c))
|
||||||
return monitor_write_error(c, "Invalid command");
|
return monitor_write_error(c, "Invalid command");
|
||||||
return 0;
|
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 monitor_announce_bundle(rhizome_manifest *m)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -39,11 +39,11 @@ int overlay_packetradio_setup_port(overlay_interface *interface)
|
|||||||
tcsetattr(interface->alarm.poll.fd, TCSANOW, &t);
|
tcsetattr(interface->alarm.poll.fd, TCSANOW, &t);
|
||||||
|
|
||||||
// Ask radio to report RSSI
|
// Ask radio to report RSSI
|
||||||
write(interface->alarm.poll.fd,"\r",1);
|
(void)write_all(interface->alarm.poll.fd,"\r",1);
|
||||||
usleep(1200000);
|
usleep(1200000);
|
||||||
write(interface->alarm.poll.fd,"+++",3);
|
(void)write_all(interface->alarm.poll.fd,"+++",3);
|
||||||
usleep(1200000);
|
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) {
|
if (config.debug.packetradio) {
|
||||||
DEBUGF("Enabled RSSI reporting for RFD900 radios");
|
DEBUGF("Enabled RSSI reporting for RFD900 radios");
|
||||||
DEBUGF("Sent ATO to make sure we are in on-line mode");
|
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;
|
int i;
|
||||||
for (i=0;i<sizeof buff;i++)
|
for (i=0;i<sizeof buff;i++)
|
||||||
buff[i]=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);
|
set_nonblock(interface->alarm.poll.fd);
|
||||||
|
@ -378,10 +378,7 @@ int rhizome_direct_process_mime_line(rhizome_http_request *r,char *buffer,int co
|
|||||||
r->field_file=fopen(filename,"w");
|
r->field_file=fopen(filename,"w");
|
||||||
if (!r->field_file) {
|
if (!r->field_file) {
|
||||||
WHYF_perror("fopen(%s, \"w\")", alloca_str_toprint(filename));
|
WHYF_perror("fopen(%s, \"w\")", alloca_str_toprint(filename));
|
||||||
rhizome_direct_clear_temporary_files(r);
|
goto scram;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
r->source_flags=RD_MIME_STATE_BODY;
|
r->source_flags=RD_MIME_STATE_BODY;
|
||||||
} else {
|
} else {
|
||||||
@ -414,15 +411,23 @@ int rhizome_direct_process_mime_line(rhizome_http_request *r,char *buffer,int co
|
|||||||
case RD_MIME_STATE_BODY:
|
case RD_MIME_STATE_BODY:
|
||||||
if (boundaryLine) {
|
if (boundaryLine) {
|
||||||
r->source_flags=RD_MIME_STATE_PARTHEADERS;
|
r->source_flags=RD_MIME_STATE_PARTHEADERS;
|
||||||
|
/* We will have written an extra CRLF to the end of the file, so prune that off. */
|
||||||
/* We will have written an extra CRLF to the end of the file,
|
if (fflush(r->field_file) == EOF) {
|
||||||
so prune that off. */
|
WHYF_perror("fflush()");
|
||||||
fflush(r->field_file);
|
goto scram;
|
||||||
int fd=fileno(r->field_file);
|
}
|
||||||
off_t correct_size=ftell(r->field_file)-2;
|
int fd = fileno(r->field_file);
|
||||||
ftruncate(fd,correct_size);
|
off_t correct_size = ftell(r->field_file) - 2;
|
||||||
fclose(r->field_file);
|
if (ftruncate(fd,correct_size) == -1) {
|
||||||
r->field_file=NULL;
|
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 {
|
else {
|
||||||
int written=fwrite(r->request,count,1,r->field_file);
|
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 rhizome_direct_form_received(r);
|
||||||
}
|
}
|
||||||
return 0;
|
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)
|
int rhizome_direct_process_post_multipart_bytes(rhizome_http_request *r,const char *bytes,int count)
|
||||||
|
3
server.c
3
server.c
@ -65,9 +65,8 @@ int server_pid()
|
|||||||
FILE *f = NULL;
|
FILE *f = NULL;
|
||||||
if ((f = fopen(filename, "r"))) {
|
if ((f = fopen(filename, "r"))) {
|
||||||
char buf[20];
|
char buf[20];
|
||||||
fgets(buf, sizeof buf, f);
|
int pid = (fgets(buf, sizeof buf, f) != NULL) ? atoi(buf) : -1;
|
||||||
fclose(f);
|
fclose(f);
|
||||||
int pid = atoi(buf);
|
|
||||||
if (pid > 0 && kill(pid, 0) != -1)
|
if (pid > 0 && kill(pid, 0) != -1)
|
||||||
return pid;
|
return pid;
|
||||||
INFOF("Unlinking stale pidfile %s", filename);
|
INFOF("Unlinking stale pidfile %s", filename);
|
||||||
|
33
srandomdev.c
33
srandomdev.c
@ -56,6 +56,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
#include "log.h"
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
@ -63,22 +64,24 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
void
|
void
|
||||||
srandomdev(void)
|
srandomdev(void)
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
unsigned int seed;
|
||||||
unsigned int seed;
|
int seeded = 0;
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
FILE *fd;
|
FILE *fd;
|
||||||
|
fd = fopen("/dev/urandom", "r");
|
||||||
fd = fopen("/dev/urandom", "r");
|
if (fd >= 0) {
|
||||||
if (fd >= 0) {
|
if (fread(&seed, sizeof seed, 1, fd) != 1)
|
||||||
fread(&seed, sizeof seed, 1, fd);
|
WARNF("fread(\"/dev/urandom\") failed -- falling back to gettimeofday()");
|
||||||
fclose(fd);
|
else
|
||||||
} else
|
seeded = 1;
|
||||||
|
fclose(fd);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
{
|
if (!seeded) {
|
||||||
|
struct timeval tv;
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
seed = (getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec;
|
seed = (getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec;
|
||||||
}
|
}
|
||||||
srandom(seed);
|
srandom(seed);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user