Initial stab at porting to Solaris.

It compiles without warning (with CC=gcc) but doesn't link
because NaCL doesn't build yet.
This commit is contained in:
Paul Gardner-Stephen 2012-09-05 18:53:22 +09:30
parent ed7edd3865
commit bba6839656
26 changed files with 147 additions and 43 deletions

View File

@ -1,7 +1,5 @@
SRCS= \
audiodevices.c \
audio_alsa.c \
audio_msm_g1.c \
audio_reflector.c \
batman.c \
ciphers.c \
@ -61,6 +59,12 @@ SRCS= \
vomp.c \
xprintf.c
# Only build these on Linux
ifeq (0, 1)
SRCS+= audio_alsa.c \
audio_msm_g1.c
endif
MONITORCLIENTSRCS=conf.c \
log.c \
mkdir.c \
@ -95,11 +99,14 @@ HDRS= fifo.h \
monitor-client.h \
sqlite-amalgamation-3070900/sqlite3.h
LDFLAGS=@LDFLAGS@ @PORTAUDIO_LIBS@ @SRC_LIBS@ @SPANDSP_LIBS@ @CODEC2_LIBS@ @PTHREAD_LIBS@
LDFLAGS=@LDFLAGS@ @LIBS@ @PORTAUDIO_LIBS@ @SRC_LIBS@ @SPANDSP_LIBS@ @CODEC2_LIBS@ @PTHREAD_LIBS@
CFLAGS= -Isqlite-amalgamation-3070900 @CPPFLAGS@ @CFLAGS@ @PORTAUDIO_CFLAGS@ @SRC_CFLAGS@ @SPANDSP_CFLAGS@ @PTHREAD_CFLAGS@ $(VOIPTEST_CFLAGS)
CFLAGS+=-fPIC
CFLAGS+=-Wall -Wno-unused-value
# Solaris magic
CFLAGS+=-DSHA2_USE_INTTYPES_H -D_XOPEN_SOURCE=600 -D_XOPEN_SOURCE_EXTENDED=1 -D__EXTENSIONS__=1
-include Makefile.dbg
DEFS= @DEFS@

View File

@ -30,8 +30,12 @@ int recordBufferSize=0;
int detectAudioDevice()
{
#ifdef ANDROID
if (!audev) audev=audio_msm_g1_detect();
#endif
#ifdef linux
if (!audev) audev=audio_alsa_detect();
#endif
if (audev) {
WHYF("Detected audio device '%s'",audev->name);
return 0;

View File

@ -17,6 +17,11 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <sys/types.h>
#include <netinet/in.h>
#include <inttypes.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <time.h>
#include "serval.h"
@ -206,9 +211,9 @@ int getBatmanPeerList(char *socket_path,struct in_addr peers[],int *peer_count,i
askagain:
/* Make socket */
sock=socket(AF_LOCAL,SOCK_STREAM,0);
sock=socket(PF_UNIX,SOCK_STREAM,0);
memset(&socket_address,0,sizeof(struct sockaddr_un));
socket_address.sun_family=AF_LOCAL;
socket_address.sun_family=PF_UNIX;
if (strlen(socket_path)>256) return WHY("BATMAN socket path too long");
strcpy(socket_address.sun_path,socket_path);

View File

@ -17,6 +17,10 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "serval.h"
int sock = -1;

View File

@ -662,7 +662,9 @@ int app_server_start(int argc, const char *const *argv, struct command_line_opti
creates a new server daemon process with the correct argv[0]. Otherwise, the servald
process appears as a process with argv[0] = "org.servalproject". */
if (execpath) {
execl(execpath, execpath, "start", "foreground", NULL);
/* XXX: Need the cast on Solaris because it defins NULL as 0L and gcc doesn't
* see it as a sentinal */
execl(execpath, execpath, "start", "foreground", (void *)NULL);
_exit(-1);
}
_exit(server(NULL));
@ -672,10 +674,7 @@ int app_server_start(int argc, const char *const *argv, struct command_line_opti
/* Main process. Allow a few seconds for the child process to report for duty. */
time_ms_t timeout = gettime_ms() + 5000;
do {
struct timespec delay;
delay.tv_sec = 0;
delay.tv_nsec = 200000000; // 200 ms = 5 Hz
nanosleep(&delay, NULL);
sleep_ms(200); // 5 Hz
} while ((pid = server_pid()) == 0 && gettime_ms() < timeout);
if (pid == -1)
return -1;

2
config.guess vendored
View File

@ -1 +1 @@
/usr/share/libtool/config/config.guess
/opt/csw/share/libtool/config/config.guess

2
config.sub vendored
View File

@ -1 +1 @@
/usr/share/libtool/config/config.sub
/opt/csw/share/libtool/config/config.sub

View File

@ -59,8 +59,15 @@ if test -n "$JAVAC"; then
popdef([AC_MSG_ERROR])
fi
dnl XXX Isn't this pointless? we are always linked against libc
AC_CHECK_LIB(c,srandomdev)
dnl Solaris hides nanosleep here
AC_CHECK_LIB(rt,nanosleep)
dnl BSD way of getting socket creds
AC_CHECK_FUNC(getpeereid)
AC_CHECK_HEADERS(
stdio.h \
errno.h \
@ -86,6 +93,10 @@ AC_CHECK_HEADERS(
signal.h \
jni.h \
alsa/asoundlib.h \
ucred.h \
sys/filio.h \
sys/endian.h \
sys/byteorder.h \
)
echo "Fetching and building NaCl if required."

View File

@ -179,7 +179,9 @@ dna_helper_start(const char *command, const char *arg, const char *mysid)
fflush(stderr);
_exit(-1);
}
execl(command, command, arg, NULL);
/* XXX: Need the cast on Solaris because it defins NULL as 0L and gcc doesn't
* see it as a sentinal */
execl(command, command, arg, (void *)NULL);
LOGF_perror(LOG_LEVEL_FATAL, "execl(%s, %s, %s, NULL)", command, command, arg ? arg : "NULL");
fflush(stderr);
do { _exit(-1); } while (1);

View File

@ -74,7 +74,9 @@ static int safeSystem(char *cmd_file)
if(pid == -1)
return WHY_perror("fork");
if (pid == 0) {
execlp(shell, shell, "-c", cmd_file,NULL);
/* XXX: Need the cast on Solaris because it defins NULL as 0L and gcc doesn't
* see it as a sentinal */
execlp(shell, shell, "-c", cmd_file,(void*)NULL);
_exit(1);
}
// Wait for child to finish

View File

@ -1 +1 @@
/usr/share/libtool/config/install-sh
/opt/csw/share/libtool/config/install-sh

View File

@ -1125,7 +1125,7 @@ unsigned char *keyring_find_sas_private(keyring_file *k,unsigned char *sid,
int cn=0,in=0,kp=0;
if (!keyring_find_sid(k,&cn,&in,&kp,sid)) {
RETURN(WHYNULL("Could not find SID in keyring, so can't find SAS"));
RETURNNULL(WHYNULL("Could not find SID in keyring, so can't find SAS"));
}
for(kp=0;kp<k->contexts[cn]->identities[in]->keypair_count;kp++)
@ -1139,7 +1139,7 @@ unsigned char *keyring_find_sas_private(keyring_file *k,unsigned char *sid,
RETURN(k->contexts[cn]->identities[in]->keypairs[kp]->private_key);
}
RETURN(WHYNULL("Identity lacks SAS"));
RETURNNULL(WHYNULL("Identity lacks SAS"));
}
struct sid_sas_mapping {
@ -1329,11 +1329,11 @@ unsigned char *keyring_find_sas_public(keyring_file *k,unsigned char *sid)
==KEYTYPE_CRYPTOBOX)
bcopy(keyring->contexts[0]->identities[0]->keypairs[0]->public_key,
mdp.out.src.sid,SID_SIZE);
else { RETURN(WHYNULL("couldn't request SAS (I don't know who I am)")); }
else { RETURNNULL(WHYNULL("couldn't request SAS (I don't know who I am)")); }
mdp.out.payload_length=1;
mdp.out.payload[0]=KEYTYPE_CRYPTOSIGN;
if (overlay_mdp_dispatch(&mdp, 0 /* system generated */, NULL, 0))
RETURN(WHYNULL("Failed to send SAS resolution request"));
RETURNNULL(WHYNULL("Failed to send SAS resolution request"));
if (debug & DEBUG_KEYRING)
DEBUGF("Dispatched SAS resolution request");
RETURN(NULL);
@ -1458,9 +1458,9 @@ struct nm_record nm_cache[NM_CACHE_SLOTS];
unsigned char *keyring_get_nm_bytes(sockaddr_mdp *known,sockaddr_mdp *unknown)
{
IN();
if (!known) { RETURN(WHYNULL("known pub key is null")); }
if (!unknown) { RETURN(WHYNULL("unknown pub key is null")); }
if (!keyring) { RETURN(WHYNULL("keyring is null")); }
if (!known) { RETURNNULL(WHYNULL("known pub key is null")); }
if (!unknown) { RETURNNULL(WHYNULL("unknown pub key is null")); }
if (!keyring) { RETURNNULL(WHYNULL("keyring is null")); }
int i;
@ -1478,7 +1478,7 @@ unsigned char *keyring_get_nm_bytes(sockaddr_mdp *known,sockaddr_mdp *unknown)
in fact a known key */
int cn=0,in=0,kp=0;
if (!keyring_find_sid(keyring,&cn,&in,&kp,known->sid))
{ RETURN(WHYNULL("known key is not in fact known.")); }
{ RETURNNULL(WHYNULL("known key is not in fact known.")); }
/* work out where to store it */
if (nm_slots_used<NM_CACHE_SLOTS) {

17
log.c
View File

@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/param.h>
#include <time.h>
#ifdef __APPLE__
#include <mach-o/dyld.h>
@ -400,15 +401,15 @@ ssize_t get_self_executable_path(char *buf, size_t len)
int log_backtrace(struct __sourceloc where)
{
open_logging();
char execpath[160];
char execpath[MAXPATHLEN];
if (get_self_executable_path(execpath, sizeof execpath) == -1)
return WHY("cannot log backtrace: own executable path unknown");
char tempfile[512];
if (!FORM_SERVAL_INSTANCE_PATH(tempfile, "servalXXXXXX.gdb"))
char tempfile[MAXPATHLEN];
if (!FORM_SERVAL_INSTANCE_PATH(tempfile, "servalgdb.XXXXX"))
return -1;
int tmpfd = mkstemps(tempfile, 4);
int tmpfd = mkstemp(tempfile);
if (tmpfd == -1)
return WHY_perror("mkstemps");
return WHY_perror("mkstemp");
if (write_str(tmpfd, "backtrace\n") == -1) {
close(tmpfd);
unlink(tempfile);
@ -420,7 +421,7 @@ int log_backtrace(struct __sourceloc where)
return -1;
}
char pidstr[12];
snprintf(pidstr, sizeof pidstr, "%u", getpid());
snprintf(pidstr, sizeof pidstr, "%jd", (intmax_t)getpid());
int stdout_fds[2];
if (pipe(stdout_fds) == -1)
return WHY_perror("pipe");
@ -442,7 +443,9 @@ int log_backtrace(struct __sourceloc where)
_exit(-2);
}
close(stdout_fds[0]);
execlp("gdb", "gdb", "-n", "-batch", "-x", tempfile, execpath, pidstr, NULL);
/* XXX: Need the cast on Solaris because it defins NULL as 0L and gcc doesn't
* see it as a sentinal */
execlp("gdb", "gdb", "-n", "-batch", "-x", tempfile, execpath, pidstr, (void*)NULL);
perror("execlp(\"gdb\")");
do { _exit(-3); } while (1);
break;

View File

@ -1 +1 @@
/usr/share/libtool/config/ltmain.sh
/opt/csw/share/libtool/config/ltmain.sh

View File

@ -27,6 +27,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "rhizome.h"
#include <sys/stat.h>
#ifdef HAVE_UCRED_H
#include <ucred.h>
#endif
#if defined(LOCAL_PEERCRED) && !defined(SO_PEERCRED)
#define SO_PEERCRED LOCAL_PEERCRED
#endif
@ -263,12 +267,14 @@ void monitor_client_poll(struct sched_ent *alarm)
}
static void monitor_new_client(int s) {
#ifdef linux
#ifdef SO_PEERCRED
struct ucred ucred;
socklen_t len;
int res;
#else
#elif defined(HAVE_GETPEEREID)
gid_t othergid;
#elif defined(HAVE_UCRED_H)
ucred_t *ucred;
#endif
uid_t otheruid;
struct monitor_context *c;
@ -276,7 +282,8 @@ static void monitor_new_client(int s) {
if (set_nonblock(s) == -1)
goto error;
#ifdef linux
#ifdef SO_PEERCRED
/* Linux way */
len = sizeof(ucred);
res = getsockopt(s, SOL_SOCKET, SO_PEERCRED, &ucred, &len);
if (res) {
@ -288,11 +295,22 @@ static void monitor_new_client(int s) {
goto error;
}
otheruid = ucred.uid;
#else
#elif defined(HAVE_UCRED_H)
/* Solaris way */
if (getpeerucred(s, &ucred) != 0) {
WHY_perror("getpeerucred()");
goto error;
}
otheruid = ucred_geteuid(ucred);
ucred_free(ucred);
#elif defined(HAVE_GETPEEREID)
/* BSD way */
if (getpeereid(s, &otheruid, &othergid) != 0) {
WHY_perror("getpeereid()");
goto error;
}
#else
#error No way to get socket peer credentials
#endif
if (otheruid != getuid()) {

View File

@ -17,6 +17,10 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <assert.h>
#include <time.h>
#include "serval.h"
@ -219,7 +223,13 @@ int overlay_bind_socket(const struct sockaddr *addr, size_t addr_size, char *int
/* Automatically close socket on calls to exec().
This makes life easier when we restart with an exec after receiving
a bad signal. */
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, NULL) | O_CLOEXEC);
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, NULL) |
#ifdef FD_CLOEXEC
FD_CLOEXEC
#else
O_CLOEXEC
#endif
);
#ifdef SO_BINDTODEVICE
/*

View File

@ -291,7 +291,7 @@ unsigned char *overlay_mdp_decrypt(overlay_frame *f, overlay_mdp_frame *mdp, int
mdp->packetTypeAndFlags|=MDP_NOCRYPT|MDP_NOSIGN;
break;
case OF_CRYPTO_CIPHERED:
RETURN(WHYNULL("decryption not implemented"));
RETURNNULL(WHYNULL("decryption not implemented"));
mdp->packetTypeAndFlags|=MDP_NOSIGN;
break;
case OF_CRYPTO_SIGNED:
@ -301,7 +301,7 @@ unsigned char *overlay_mdp_decrypt(overlay_frame *f, overlay_mdp_frame *mdp, int
is not available. */
unsigned char *key = keyring_find_sas_public(keyring,mdp->out.src.sid);
if (!key)
RETURN(WHYNULL("SAS key not currently on record, cannot verify"));
RETURNNULL(WHYNULL("SAS key not currently on record, cannot verify"));
/* get payload and following compacted signature */
b=&f->payload->bytes[0];

View File

@ -298,19 +298,24 @@ overlay_frame *op_dup(overlay_frame *in)
/* clone the frame */
overlay_frame *out=malloc(sizeof(overlay_frame));
if (!out) return WHYNULL("malloc() failed");
if (!out) {
WHY("malloc() failed");
return NULL;
}
/* copy main data structure */
bcopy(in,out,sizeof(overlay_frame));
out->payload=ob_new(in->payload->length);
if (!out->payload) {
free(out);
return WHYNULL("ob_new() failed");
WHY("ob_new() failed");
return NULL;
}
if (ob_append_bytes(out->payload,&in->payload->bytes[0],in->payload->length))
{
op_free(out);
return WHYNULL("could not duplicate payload bytes");
WHY("could not duplicate payload bytes");
return NULL;
}
return out;
}

View File

@ -17,6 +17,10 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "serval.h"
char *batman_socket=NULL;

View File

@ -872,7 +872,7 @@ int rhizome_store_file(rhizome_manifest *m,const unsigned char *key)
WARNF("File has grown by %lld bytes. I will just store the original number of bytes so that the hash (hopefully) matches",stat.st_size-m->fileLength);
}
unsigned char *addr = mmap(NULL, m->fileLength, PROT_READ, MAP_FILE|MAP_SHARED, fd, 0);
unsigned char *addr = mmap(NULL, m->fileLength, PROT_READ, MAP_SHARED, fd, 0);
if (addr==MAP_FAILED) {
WHY_perror("mmap");
WHY("mmap() of associated file failed.");

View File

@ -20,6 +20,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <sys/types.h>
#include <sys/socket.h>
#include <signal.h>
#ifdef HAVE_SYS_FILIO_H
#include <sys/filio.h>
#endif
#include "serval.h"
#include "str.h"

View File

@ -21,6 +21,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "rhizome.h"
#include <assert.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int rhizome_manifest_to_bar(rhizome_manifest *m,unsigned char *bar)
{

View File

@ -1163,5 +1163,6 @@ void dump_stack();
#define OUT() fd_func_exit(&_this_call);
#define RETURN(X) { OUT() return(X); }
#define RETURNNULL { OUT() return(NULL); }
#endif // __SERVALD_SERVALD_H

View File

@ -21,6 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "xprintf.h"
#define MAX_SPACES 120

View File

@ -828,7 +828,13 @@ int createServerSocket()
This makes life easier when we restart with an exec after receiving
a bad signal. */
fcntl(sock, F_SETFL,
fcntl(sock, F_GETFL, NULL)|O_CLOEXEC);
fcntl(sock, F_GETFL, NULL)|
#ifdef FD_CLOEXEC
FD_CLOEXEC
#else
O_CLOEXEC
#endif
);
int i=1;
setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &i, sizeof(i));

14
sha2.c
View File

@ -36,8 +36,22 @@
#ifdef HAVE_SYS_ENDIAN_H
#include <sys/endian.h>
#endif
#ifdef HAVE_SYS_BYTEORDER_H
#include <sys/byteorder.h>
#endif
#include "sha2.h"
/* Translate from Solaris */
#ifndef BYTE_ORDER
#define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */
#define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */
#ifdef _BIG_ENDIAN
#define BYTE_ORDER BIG_ENDIAN
#else
#define BYTE_ORDER LITTLE_ENDIAN
#endif
#endif
/*
* ASSERT NOTE:
* Some sanity checking code is included using assert(). On my FreeBSD