Skip to content

Commit

Permalink
changes to compile on freebsd or old linux
Browse files Browse the repository at this point in the history
  • Loading branch information
ColumPaget committed Jun 23, 2017
1 parent 2d88711 commit b40b2a7
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 32 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
CC = gcc
CC = cc
VERSION = 1.2.1
CFLAGS = -g -O2
LIBS = -lcrypto -lssl -lz
INSTALL=/bin/install -c
LIBS = -lz
INSTALL=/usr/bin/install -c
prefix=/usr/local
bindir=$(prefix)${exec_prefix}/bin
DESTDIR=
FLAGS=$(CFLAGS) -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DSTDC_HEADERS=1 -DHAVE_LIBZ=1 -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 -DHAVE_LIBSSL=1 -DHAVE_LIBCRYPTO=1
FLAGS=$(CFLAGS) -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DSTDC_HEADERS=1 -DHAVE_LIBZ=1 -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64
OBJ=common.o settings.o containerfiles.o outputfiles.o servicetypes.o extract_text.o download.o display.o players.o selectformat.o ehow.o ign.o youtube.o

all: $(OBJ)
Expand Down
44 changes: 37 additions & 7 deletions libUseful-2.8/FileSystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
//#include <sys/ioctl.h>
//#include <sys/resource.h>
#include <sys/mount.h>

#ifdef linux
#include <sys/xattr.h>
#endif

const char *GetBasename(const char *Path)
{
Expand Down Expand Up @@ -224,22 +227,28 @@ char *FileGetXAttribute(char *RetStr, const char *Path, const char *Name)
{
int len;

#ifdef linux
len=getxattr(Path, Name, NULL, 0);
if (len > 0)
{
RetStr=SetStrLen(RetStr,len);
getxattr(Path, Name, RetStr, len);
}
else RetStr=CopyStr(RetStr, "");
#endif

return(RetStr);
}


int FileSetXAttribute(const char *Path, const char *Name, const char *Value, int Len)
{
#ifdef linux
if (Len==0) Len=StrLen(Value);
return(setxattr(Path, Name, Value, Len, 0));
#endif

return(-1);
}


Expand All @@ -261,35 +270,56 @@ else p_MountPoint=MountPoint;

if (! StrValid(p_MountPoint)) return(FALSE);

#ifdef MS_BIND
if (strcmp(Type,"bind")==0)
{
p_Type="";
Flags=MS_BIND;
}
#endif


ptr=GetToken(Args, " |,", &Token, GETTOKEN_MULTI_SEP);
while (ptr)
{
#ifdef MS_RDONLY
if (strcmp(Token,"ro")==0) Flags |= MS_RDONLY;
else if (strcmp(Token,"noexec")==0) Flags |= MS_NOEXEC;
else if (strcmp(Token,"nosuid")==0) Flags |= MS_NOSUID;
else if (strcmp(Token,"nodev")==0) Flags |= MS_NODEV;
else if (strncmp(Token,"perms=",6)==0) Perms=strtol(Token+6,NULL,8);
#endif

#ifdef MS_NOEXEC
if (strcmp(Token,"noexec")==0) Flags |= MS_NOEXEC;
#endif

#ifdef MS_NOSUID
if (strcmp(Token,"nosuid")==0) Flags |= MS_NOSUID;
#endif

#ifdef MS_NODEV
if (strcmp(Token,"nodev")==0) Flags |= MS_NODEV;
#endif

if (strncmp(Token,"perms=",6)==0) Perms=strtol(Token+6,NULL,8);
ptr=GetToken(ptr, " |,", &Token, GETTOKEN_MULTI_SEP);
}

Token=MCopyStr(Token,p_MountPoint,"/",NULL);
MakeDirPath(Token,Perms);

//must do a little dance for readonly bind mounts. We must first mount, then remount readonly
#ifdef MS_BIND
if ((Flags & MS_BIND) && (Flags & MS_RDONLY))
{
mount(Dev,p_MountPoint,"",MS_BIND,NULL);
Flags |= MS_REMOUNT;
}
#endif

#ifdef linux
result=mount(Dev,p_MountPoint,p_Type,Flags,NULL);
#else
//assume BSD if not linux
result=mount(p_Type,p_MountPoint,Flags,Dev);
#endif

DestroyString(Token);
return(result);
Expand All @@ -302,8 +332,8 @@ return(result);
#define UMOUNT_NOFOLLOW 0
#endif

#ifndef UMOUNT_DETACH
#define UMOUNT_DETACH 0
#ifndef MNT_DETACH
#define MNT_DETACH 0
#endif


Expand Down Expand Up @@ -352,7 +382,7 @@ if (ExtraFlags & UMOUNT_RECURSE)
#ifdef linux
result=umount2(MountPoint, Flags);
#else
result=umount(MountPoint);
result=unmount(MountPoint,0);
#endif

if (ExtraFlags & UMOUNT_RMDIR) rmdir(MountPoint);
Expand Down
25 changes: 11 additions & 14 deletions libUseful-2.8/GeneralFunctions.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
#include "Hash.h"
#include "Time.h"
#include <sys/utsname.h>
#include <sys/sysinfo.h>
#include <sys/file.h>
#include <math.h>
#include <pwd.h>
#include <grp.h>

#ifdef linux
#include <sys/sysinfo.h>
#endif

//xmemset uses a 'volatile' pointer so that it won't be optimized out
void xmemset(volatile char *Str, char fill, off_t size)
{
Expand Down Expand Up @@ -89,8 +92,8 @@ fd=open("/dev/urandom",O_RDONLY);
if (fd > -1)
{
RandomBytes=SetStrLen(RandomBytes,ReqLen);
len=read(fd,RandomBytes,ReqLen);
close(fd);
len=read(fd,RandomBytes,ReqLen);
close(fd);
}
else
{
Expand Down Expand Up @@ -266,12 +269,10 @@ return(grent->gr_gid);
const char *OSSysInfoString(int Info)
{
static struct utsname UtsInfo;
static struct sysinfo SysInfo;
struct passwd *pw;
const char *ptr;

uname(&UtsInfo);
sysinfo(&SysInfo);

switch (Info)
{
Expand All @@ -291,14 +292,6 @@ case OSINFO_TMPDIR:
if (ptr) return(ptr);
break;

/*
case OSINFO_UPTIME: MuJSNumber((double) SysInfo.uptime); break;
case OSINFO_TOTALMEM: MuJSNumber((double) SysInfo.totalram); break;
case OSINFO_FREEMEM: MuJSNumber((double) SysInfo.freeram); break;
case OSINFO_PROCS: MuJSNumber((double) SysInfo.procs); break;
case OSINFO_LOAD: MuJSArray(TYPE_ULONG, 3, (void *) SysInfo.loads); break;
*/


/*
case OSINFO_USERINFO:
Expand Down Expand Up @@ -327,6 +320,7 @@ return("");
//lua that have an 'os' object that returns information
unsigned long OSSysInfoLong(int Info)
{
#ifdef linux
struct utsname UtsInfo;
struct sysinfo SysInfo;
struct passwd *pw;
Expand All @@ -342,6 +336,9 @@ case OSINFO_TOTALMEM: return((unsigned long) SysInfo.totalram); break;
case OSINFO_FREEMEM: return((unsigned long) SysInfo.freeram); break;
case OSINFO_PROCS: return((unsigned long) SysInfo.procs); break;
//case OSINFO_LOAD: MuJSArray(TYPE_ULONG, 3, (void *) SysInfo.loads); break;
return(0);

}

#endif
return(0);
}
6 changes: 3 additions & 3 deletions libUseful-2.8/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CC = gcc
CC = cc
VERSION = 0.0.1
CFLAGS = -g -O2
LIBS = -lz -lcrypto -lssl -lc
FLAGS=$(LDFLAGS) $(CPPFLAGS) $(CFLAGS) -fPIC -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DSTDC_HEADERS=1 -D_FILE_OFFSET_BITS=64 -DHAVE_LIBC=1 -DHAVE_PTSNAME_R=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DUSE_SENDFILE=1 -DHAVE_LIBSSL=1 -DHAVE_LIBCRYPTO=1 -DHAVE_EVP_BF_CBC=1 -DHAVE_EVP_RC2_CBC=1 -DHAVE_EVP_RC4=1 -DHAVE_EVP_DES_CBC=1 -DHAVE_EVP_DESX_CBC=1 -DHAVE_EVP_CAST5_CBC=1 -DHAVE_EVP_IDEA_CBC=1 -DHAVE_EVP_AES_128_CBC=1 -DHAVE_EVP_AES_256_CBC=1 -DUSE_OPENSSL_ADD_ALL_ALGORITHMS=1 -DHAVE_LIBZ=1 -DHAVE_OSS=1 -DHAVE_MADVISE -DHAVE_MADVISE_NOFORK -DHAVE_MADVISE_DONTDUMP -DHAVE_MLOCK
LIBS =
FLAGS=$(LDFLAGS) $(CPPFLAGS) $(CFLAGS) -fPIC -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DSTDC_HEADERS=1 -DHAVE_PTSNAME_R=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_OSS=1 -DHAVE_MADVISE -DHAVE_MADVISE_NOFORK -DHAVE_MADVISE_DONTDUMP -DHAVE_MLOCK
prefix=/usr/local
OBJ=string.o list.o socket.o unix_socket.o file.o tar.o Terminal.o FileSystem.o GeneralFunctions.o DataProcessing.o EncryptedFiles.o g711.o sound.o pty.o Log.o http.o inet.o expect.o base64.o crc32.o md5c.o sha1.o sha2.o whirlpool.o jh_ref.o Hash.o ssh.o Compression.o oauth.o libsettings.o Vars.o Time.o Markup.o SpawnPrograms.o Tokenizer.o PatternMatch.o URL.o DataParser.o ConnectionChain.o openssl.o Process.o Encodings.o RawData.o securemem.o

Expand Down
21 changes: 18 additions & 3 deletions libUseful-2.8/Process.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "FileSystem.h"
#include "Log.h"
#include <sched.h>
#include <wait.h>
#include <sys/wait.h>


/*This is code to change the command-line of a program as visible in ps */
Expand Down Expand Up @@ -261,8 +261,8 @@ struct sigaction sa;
}

waitpid(Child,NULL,0);
umount("/proc");
rmdir("/proc");

FileSystemUnMount("/proc","rmdir");
FileSystemUnMount("/","recurse,rmdir");

STREAMClose(TunS);
Expand Down Expand Up @@ -305,23 +305,38 @@ ptr=GetNameValuePair(ptr,"\\S","=",&Name,&Value);
pid=getpid();

#ifdef linux
#ifdef CLONE_NEWPID
unshare(CLONE_NEWPID);
#endif

//fork again because CLONE_NEWPID only takes effect after another fork, and creates an 'init' process
child=fork();
if (child==0)
{
#ifdef CLONE_NEWNET
if (! (Flags & PROC_CONTAINER_NET)) unshare(CLONE_NEWNET);
#endif

//do these all individually because any one of them might be rejected
#ifdef CLONE_NEWIPC
unshare(CLONE_NEWIPC);
#endif

#ifdef CLONE_NEWUTS
unshare(CLONE_NEWUTS);
#endif

#ifdef CLONE_FS
unshare(CLONE_FS);
#endif

val=StrLen(HostName);
if (val != 0) sethostname(HostName, val);
else sethostname("container", 9);

#ifdef CLONE_NEWNS
unshare(CLONE_NEWNS);
#endif
}
else ProcessContainerInit(-1, -1, child);
#endif
Expand Down
2 changes: 1 addition & 1 deletion libUseful-2.8/Vars.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ListNode *SetDetailVar(ListNode *Vars, const char *Name, const char *Data, int I
ListNode *Node;
char *Tempstr=NULL;

if (! Vars) return;
if (! Vars) return(NULL);
Tempstr=CopyStr(Tempstr,Name);
//strlwr(Tempstr);
Node=ListFindNamedItem(Vars,Tempstr);
Expand Down
3 changes: 3 additions & 0 deletions libUseful-2.8/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
#include "securemem.h"
#include <sys/mman.h>
#include <sys/ioctl.h>

#ifdef linux
#include <linux/fs.h>
#endif

#ifdef HAVE_LIBSSL
#include <openssl/crypto.h>
Expand Down
3 changes: 3 additions & 0 deletions youtube.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ ptr=GetToken(Formats,",",&Token,0);
while (ptr)
{
YouTubeFormatGetData(Token, &URL, &TypeCode, Vars);
if (StrValid(TypeCode))
{
switch (atoi(TypeCode))
{
case 5:
Expand Down Expand Up @@ -161,6 +163,7 @@ while (ptr)
if (StrValid(ptr)) fprintf(stderr,"Unknown youtube format [%s]\n",Token);
break;
}
}
ptr=GetToken(ptr,",",&Token,0);
}

Expand Down

0 comments on commit b40b2a7

Please sign in to comment.