Skip to content

Commit

Permalink
- Separated log stuff in different files
Browse files Browse the repository at this point in the history
- Added function to detect the disk space
- Fixed bug in parser to find the installation size
  • Loading branch information
megastep committed Sep 2, 1999
1 parent 9d98c54 commit 735654e
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 67 deletions.
2 changes: 1 addition & 1 deletion Makefile
@@ -1,6 +1,6 @@


CFLAGS = -g CFLAGS = -g
OBJS = main.o console_ui.o install.o detect.o copy.o file.o log.o OBJS = main.o console_ui.o install.o detect.o copy.o file.o log.o install_log.o
LIBS = -lxml -lz LIBS = -lxml -lz


all: testxml setup all: testxml setup
Expand Down
2 changes: 1 addition & 1 deletion console_ui.c
Expand Up @@ -104,7 +104,7 @@ static void parse_option(install_info *info, xmlNodePtr node)
mark_option(info, node, "true", 0); mark_option(info, node, "true", 0);


/* Add this option size to the total */ /* Add this option size to the total */
sizestr = xmlGetProp(node, "install"); sizestr = xmlGetProp(node, "size");
if ( sizestr ) { if ( sizestr ) {
info->install_size += atoi(sizestr); info->install_size += atoi(sizestr);
} }
Expand Down
60 changes: 58 additions & 2 deletions detect.c
@@ -1,6 +1,7 @@


#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <limits.h>


#include "detect.h" #include "detect.h"


Expand Down Expand Up @@ -65,8 +66,63 @@ const char *detect_libc(void)




/* Function to detect the MB of diskspace on a path */ /* Function to detect the MB of diskspace on a path */
/* Ripped straight from the Myth II GUI installer */
/* The upper directory in the path must be valid ! */
int detect_diskspace(const char *path) int detect_diskspace(const char *path)
{ {
#warning FIXME Stephane! :) int fd[ 2 ];
return(0); int pid;
int len;
char *arg[ 4 ];
char buf[ 1024 ], path_up[PATH_MAX];
char *cp;
char *end;

strcpy(path_up, path);
cp = (char*)rindex(path_up, '/');
if(cp)
*cp = '\0';

pipe( fd );

pid = fork();
if( pid == -1 )
return -1;

if( pid == 0 ) {
arg[ 0 ] = "df";
arg[ 1 ] = "-m";
arg[ 2 ] = (char*) path_up;
arg[ 3 ] = 0;

close( 1 ); /* close normal stdout */
dup( fd[1] ); /* make stdout same as pfds[1] */
close( fd[0] ); /* we don't need this */
execvp( "df", arg );
perror( "exec df" );
exit(-1);
} else {
close( fd[1] ); /* we don't need this */
len = read( fd[0], buf, sizeof(buf) );
close( fd[0] );
}

if( len > 0 ) {
// Checking if df is reporting an error of some sort.
if( strcmp( buf, "df:" ) == 0 ) {
fprintf( stderr, buf );
return -1;
}

// Skip report header line.
cp = buf;
end = cp + len;
while( (cp < end) && (*cp != '\n') ) {
cp++;
}

sscanf( cp, "%*s %*d %*d %d %*s %*s", &len );
}

return len;
} }
54 changes: 1 addition & 53 deletions file.c
Expand Up @@ -14,58 +14,6 @@


#include "file.h" #include "file.h"


void log_debug(install_info *info, const char *fmt, ...)
{
va_list ap;
char buf[BUFSIZ];

va_start(ap, fmt);
vsprintf(buf, fmt, ap);
va_end(ap);
print_log(info->log, LOG_DEBUG, "%s\n", buf);
}
void log_quiet(install_info *info, const char *fmt, ...)
{
va_list ap;
char buf[BUFSIZ];

va_start(ap, fmt);
vsprintf(buf, fmt, ap);
va_end(ap);
print_log(info->log, LOG_QUIET, "%s\n", buf);
}
void log_normal(install_info *info, const char *fmt, ...)
{
va_list ap;
char buf[BUFSIZ];

va_start(ap, fmt);
vsprintf(buf, fmt, ap);
va_end(ap);
print_log(info->log, LOG_NORMAL, "%s\n", buf);
}
void log_warning(install_info *info, const char *fmt, ...)
{
va_list ap;
char buf[BUFSIZ];

va_start(ap, fmt);
vsprintf(buf, fmt, ap);
va_end(ap);
print_log(info->log, LOG_WARNING, "%s\n", buf);
}
void log_fatal(install_info *info, const char *fmt, ...)
{
va_list ap;
char buf[BUFSIZ];

va_start(ap, fmt);
vsprintf(buf, fmt, ap);
va_end(ap);
print_log(info->log, LOG_FATAL, "%s\n", buf);
abort();
}

stream *file_open(install_info *info, const char *path, const char *mode) stream *file_open(install_info *info, const char *path, const char *mode)
{ {
stream *streamp; stream *streamp;
Expand Down Expand Up @@ -257,7 +205,7 @@ int file_mkdir(install_info *info, const char *path, int mode)


/* Only create the directory if we need to */ /* Only create the directory if we need to */
retval = 0; retval = 0;
if ( (stat(path, &sb) != 0) || S_ISDIR(sb.st_mode) ) { if ( (stat(path, &sb) != 0) || !S_ISDIR(sb.st_mode) ) {
/* Log the action */ /* Log the action */
log_quiet(info, "Creating directory: %s\n", path); log_quiet(info, "Creating directory: %s\n", path);


Expand Down
6 changes: 0 additions & 6 deletions file.h
Expand Up @@ -16,12 +16,6 @@ typedef struct {
gzFile zfp; gzFile zfp;
} stream; } stream;


extern void log_debug(install_info *info, const char *fmt, ...);
extern void log_quiet(install_info *info, const char *fmt, ...);
extern void log_normal(install_info *info, const char *fmt, ...);
extern void log_warning(install_info *info, const char *fmt, ...);
extern void log_fatal(install_info *info, const char *fmt, ...);

extern stream *file_open(install_info *info,const char *path,const char *mode); extern stream *file_open(install_info *info,const char *path,const char *mode);
extern int file_read(install_info *info, void *buf, int len, stream *streamp); extern int file_read(install_info *info, void *buf, int len, stream *streamp);
extern int file_write(install_info *info, void *buf, int len, stream *streamp); extern int file_write(install_info *info, void *buf, int len, stream *streamp);
Expand Down
2 changes: 1 addition & 1 deletion install.c
Expand Up @@ -6,7 +6,7 @@


#include "install.h" #include "install.h"
#include "detect.h" #include "detect.h"

#include "log.h"


/* Functions to retrieve attribution information from the XML tree */ /* Functions to retrieve attribution information from the XML tree */
static const char *GetProductName(install_info *info) static const char *GetProductName(install_info *info)
Expand Down
5 changes: 3 additions & 2 deletions install.h
Expand Up @@ -5,8 +5,6 @@
#include <limits.h> #include <limits.h>
#include <gnome-xml/parser.h> #include <gnome-xml/parser.h>


#include "log.h"

/* The default location of the product */ /* The default location of the product */
#define DEFAULT_PATH "/usr/local/games" #define DEFAULT_PATH "/usr/local/games"


Expand All @@ -24,6 +22,9 @@ typedef enum {
/* Forward declaration (used by UI) */ /* Forward declaration (used by UI) */
struct UI_data; struct UI_data;


/* Forward declaration */
typedef struct _install_log install_log;

/* The main installation information structure */ /* The main installation information structure */
typedef struct { typedef struct {


Expand Down
59 changes: 59 additions & 0 deletions install_log.c
@@ -0,0 +1,59 @@
/* Functions to log messages */

#include <stdarg.h>
#include <stdio.h>

#include "install_log.h"
#include "log.h"

void log_debug(install_info *info, const char *fmt, ...)
{
va_list ap;
char buf[BUFSIZ];

va_start(ap, fmt);
vsprintf(buf, fmt, ap);
va_end(ap);
print_log(info->log, LOG_DEBUG, "%s\n", buf);
}
void log_quiet(install_info *info, const char *fmt, ...)
{
va_list ap;
char buf[BUFSIZ];

va_start(ap, fmt);
vsprintf(buf, fmt, ap);
va_end(ap);
print_log(info->log, LOG_QUIET, "%s\n", buf);
}
void log_normal(install_info *info, const char *fmt, ...)
{
va_list ap;
char buf[BUFSIZ];

va_start(ap, fmt);
vsprintf(buf, fmt, ap);
va_end(ap);
print_log(info->log, LOG_NORMAL, "%s\n", buf);
}
void log_warning(install_info *info, const char *fmt, ...)
{
va_list ap;
char buf[BUFSIZ];

va_start(ap, fmt);
vsprintf(buf, fmt, ap);
va_end(ap);
print_log(info->log, LOG_WARNING, "%s\n", buf);
}
void log_fatal(install_info *info, const char *fmt, ...)
{
va_list ap;
char buf[BUFSIZ];

va_start(ap, fmt);
vsprintf(buf, fmt, ap);
va_end(ap);
print_log(info->log, LOG_FATAL, "%s\n", buf);
abort();
}
14 changes: 14 additions & 0 deletions install_log.h
@@ -0,0 +1,14 @@
#ifndef _log_install_h
#define _log_install_h

/* Functions to log messages */

#include "install.h"

extern void log_debug(install_info *info, const char *fmt, ...);
extern void log_quiet(install_info *info, const char *fmt, ...);
extern void log_normal(install_info *info, const char *fmt, ...);
extern void log_warning(install_info *info, const char *fmt, ...);
extern void log_fatal(install_info *info, const char *fmt, ...);

#endif
1 change: 1 addition & 0 deletions log.c
Expand Up @@ -4,6 +4,7 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>


#include "install_log.h"
#include "log.h" #include "log.h"


struct _install_log { struct _install_log {
Expand Down
2 changes: 1 addition & 1 deletion log.h
Expand Up @@ -4,7 +4,7 @@


/* Functions to perform install logging */ /* Functions to perform install logging */


typedef struct _install_log install_log; #include "install.h"


typedef enum { typedef enum {
LOG_DEBUG, LOG_DEBUG,
Expand Down

0 comments on commit 735654e

Please sign in to comment.