Ejemplo n.º 1
0
int translate (struct filename *fn)
{
	int ret;
	char *tmpfile;

	tmpfile = gettmpname("tmp");

	// 1st: LOAD INCLUDE FILE
	com_fopen (&yyin, fn->source, "rb");
	if (!yyin) {
		perror (fn->source);
		return -1;
	}
	ret =  yyparse ();
	fclose (yyin);
	if (ret) {
		return ret;
	}
	ppoutput_incfile(fn->source, tmpfile, exec_list);

	// reset parser
	exec_list = NULL;
	yylineno = 1;
	sqlnum = 0;

	// 2nd: PARSE
	com_fopen (&yyin, tmpfile, "rb");
	if (!yyin) {
		com_unlink(tmpfile);
		perror (tmpfile);
		return -1;
	}
	ret =  yyparse ();
	fclose (yyin);
	if (ret) {
		return ret;
	}

	ppoutput(tmpfile, fn->translate, exec_list);

	return 0;
}
Ejemplo n.º 2
0
/*
 * Sets up the defragmentation of a file based on the 
 * filepath.  It collects the bstat information, does 
 * an open on the file and passes this all to fsrfile_common.
 */
static int
fsrfile(char *fname, xfs_ino_t ino)
{
	xfs_bstat_t	statbuf;
	jdm_fshandle_t	*fshandlep;
	int	fd, fsfd;
	int	error = 0;
	char	*tname;

	fshandlep = jdm_getfshandle(getparent (fname) );
	if (! fshandlep) {
		fsrprintf(
		  "unable to construct sys handle for %s: %s\n",
		  fname, strerror(errno));
		return -1;
	}

	/*
	 * Need to open something on the same filesystem as the
	 * file.  Open the parent.
	 */
	fsfd = open(getparent(fname), O_RDONLY);
	if (fsfd < 0) {
		fsrprintf(
		  "unable to open sys handle for %s: %s\n",
		  fname, strerror(errno));
		return -1;
	}
	
	if ((xfs_bulkstat_single(fsfd, &ino, &statbuf)) < 0) {
		fsrprintf(
		  "unable to get bstat on %s: %s\n",
		  fname, strerror(errno));
		close(fsfd);
		return -1;
	}
		
	fd = jdm_open( fshandlep, &statbuf, O_RDWR);
	if (fd < 0) {
		fsrprintf(
		  "unable to open handle %s: %s\n",
		  fname, strerror(errno));
		close(fsfd);
		return -1;
	}

	/* Get the fs geometry */
	if (xfs_getgeom(fsfd, &fsgeom) < 0 ) {
		fsrprintf("Unable to get geom on fs for: %s\n", fname);
		close(fsfd);
		return -1;
	}

	close(fsfd);

	tname = gettmpname(fname);

	if (tname)
		error = fsrfile_common(fname, tname, NULL, fd, &statbuf);

	close(fd);

	return error;
}
Ejemplo n.º 3
0
/**
 *  Perform crash information extraction from a single given crash entry.
 *  This function performs the lion's share of the work in processing
 *  each crash.
 *
 *  \param entry Subdirectory (of CRASH_DIR) to process
 *  \returns 0 on success, 1 on failure
 *
 *  TODO: Refactor this function to simplify it, break out the
 *  individual elements into their own function.  dsb 2011.09.07
 */
static int process_crash_item(char *entry) {
    int rc = 0;
    char cmdbuf[BUFSIZ];
    char tmp_name[PATH_MAX];
    char dmesg_output[PATH_MAX];
    char crash_input_script[PATH_MAX];
    char crash_output[PATH_MAX];
    char crash_dir[PATH_MAX];

    memset(cmdbuf, 0, BUFSIZ);
    memset(tmp_name, 0, PATH_MAX);
    memset(dmesg_output, 0, PATH_MAX);
    memset(crash_input_script, 0, PATH_MAX);
    memset(crash_output, 0, PATH_MAX);
    memset(crash_dir, 0, PATH_MAX);
    
    get_crash_dir(crash_dir, PATH_MAX);
    gettmpname(tmp_name, PATH_MAX);
    snprintf(dmesg_output, PATH_MAX-1, "%s-dmesg", tmp_name);
    snprintf(crash_input_script, PATH_MAX-1, "%s-crash-input", tmp_name);
    snprintf(crash_output, PATH_MAX-1, "%s-crash-output", tmp_name);

    /* extract dmesg contents, log to REC */
    if (is_makedumpfile_binary_available()) {
        memset(cmdbuf, 0, BUFSIZ);
        snprintf(cmdbuf, BUFSIZ-1, "%s --dump-dmesg %s/%s/vmcore %s",
                 dep.makedumpfile_bin, crash_dir, entry, dmesg_output);
        debug_log("RUN: %s", cmdbuf);
        rc += run_proc_return_result(cmdbuf, NULL);

        if (is_gzip_binary_available()) {
            memset(cmdbuf, 0, BUFSIZ);
            snprintf(cmdbuf, BUFSIZ-1, "%s --best %s", dep.gzip_bin, dmesg_output);
            debug_log("RUN: gzip --best %s", dmesg_output);
            append_gz(dmesg_output, PATH_MAX);
            rc += run_proc_return_result(cmdbuf, NULL);
        }

        debug_log("LOG: %s", dmesg_output);
        log_file_contents(dmesg_output);

        if (is_crash_binary_available()) {
            debug_log("crash is available");
            if (is_debug_symbols_available()) {
                char vmcore_loc[PATH_MAX];
                char vmlinux_loc[PATH_MAX];
                char release[PATH_MAX];

                debug_log ("Debug symbols are available");
                memset(vmcore_loc, 0, PATH_MAX);
                memset(vmlinux_loc, 0, PATH_MAX);
                memset(release, 0, PATH_MAX);

                get_release_name(release, PATH_MAX);
                
                snprintf(vmcore_loc, PATH_MAX-1, "%s/%s/vmcore", crash_dir, entry);
                snprintf(vmlinux_loc, PATH_MAX-1, dep.vmlinux_pattern, release);

                rc = write_crash_input_script(crash_input_script);
                if (!rc) {

                    memset(cmdbuf, 0, BUFSIZ);
                    snprintf(cmdbuf, BUFSIZ-1, "%s %s %s < %s > %s",
                             dep.crash_bin, vmlinux_loc, vmcore_loc, 
                             crash_input_script, crash_output);
                    
                    debug_log("RUN: %s", cmdbuf);
                    rc += run_proc_return_result(cmdbuf, NULL);

                    if (is_gzip_binary_available()) {
                        memset(cmdbuf, 0, BUFSIZ);
                        snprintf(cmdbuf, BUFSIZ-1, "%s --best %s", dep.gzip_bin, crash_output);
                        debug_log("RUN: gzip --best %s", crash_output);
                        append_gz(crash_output, PATH_MAX);

                        rc += run_proc_return_result(cmdbuf, NULL);
                    }


                    debug_log ("LOG: %s", crash_output);
                    rc = log_file_contents(crash_output);
                } else {
                    debug_log ("Failed to write crash input script.");
                    log_buffer_contents("Failed to write crash input script.");
                    rc = 1;
                }
            } else {
                debug_log ("Debug package matching the running kernel is not installed.");
                log_buffer_contents("Install the matching kernel debug package to enable the extraction of crash information.");
                rc = 1;
            }
        } else {
            debug_log ("The crash binary is not installed.");
            log_buffer_contents("Install the crash package to enable the extraction of kdump information.");
            rc = 1;
        }
    } else {
        debug_log ("The makedumpfile binary is not installed.");
        log_buffer_contents("makedumpfile is not available on this system.  Cannot extract crash information.");
        rc = 1;
    }

    /* clean up */
    if (!debug) {
        unlink(dmesg_output);
        unlink(crash_input_script);
        unlink(crash_output);
    }
    return rc;
}