error proc

/**************************************************************************                  Copyright (C) Michael Kerrisk, 2014.                   *
*                                                                         *
* This program is free software. You may use, modify, and redistribute it *
* under the terms of the GNU Lesser General Public License as published   *
* by the Free Software Foundation, either version 3 or (at your option)   *
* any later version. This program is distributed without any warranty.    *
* See the files COPYING.lgpl-v3 and COPYING.gpl-v3 for details.           *
\*************************************************************************/

/* error_functions.c

   Some standard error handling routines used by various programs.
*/
#include <stdarg.h>
#include "error_functions.h"
#include "tlpi_hdr.h"
#include "ename.c.inc"          /* Defines ename and MAX_ENAME */

#ifdef __GNUC__                 /* Prevent ‘gcc -Wall‘ complaining  */
__attribute__ ((__noreturn__))  /* if we call this function as last */
#endif                          /* statement in a non-void function */
static void
terminate(Boolean useExit3)
{
    char *s;

    /* Dump core if EF_DUMPCORE environment variable is defined and
       is a nonempty string; otherwise call exit(3) or _exit(2),
       depending on the value of ‘useExit3‘. */

    s = getenv("EF_DUMPCORE");

    if (s != NULL && *s != ‘\0‘)
        abort();
    else if (useExit3)
        exit(EXIT_FAILURE);
    else
        _exit(EXIT_FAILURE);
}

/* Diagnose ‘errno‘ error by:

      * outputting a string containing the error name (if available
        in ‘ename‘ array) corresponding to the value in ‘err‘, along
        with the corresponding error message from strerror(), and

      * outputting the caller-supplied error message specified in
        ‘format‘ and ‘ap‘. */

static void
outputError(Boolean useErr, int err, Boolean flushStdout,
        const char *format, va_list ap)
{
#define BUF_SIZE 500
    char buf[BUF_SIZE], userMsg[BUF_SIZE], errText[BUF_SIZE];

    vsnprintf(userMsg, BUF_SIZE, format, ap);

    if (useErr)
        snprintf(errText, BUF_SIZE, " [%s %s]",
                (err > 0 && err <= MAX_ENAME) ?
                ename[err] : "?UNKNOWN?", strerror(err));
    else
        snprintf(errText, BUF_SIZE, ":");

    snprintf(buf, BUF_SIZE, "ERROR%s %s\n", errText, userMsg);

    if (flushStdout)
        fflush(stdout);       /* Flush any pending stdout */
    fputs(buf, stderr);
    fflush(stderr);           /* In case stderr is not line-buffered */
}

/* Display error message including ‘errno‘ diagnostic, and
   return to caller */

void
errMsg(const char *format, ...)
{
    va_list argList;
    int savedErrno;

    savedErrno = errno;       /* In case we change it here */

    va_start(argList, format);
    outputError(TRUE, errno, TRUE, format, argList);
    va_end(argList);

    errno = savedErrno;
}

/* Display error message including ‘errno‘ diagnostic, and
   terminate the process */

void
errExit(const char *format, ...)
{
    va_list argList;

    va_start(argList, format);
    outputError(TRUE, errno, TRUE, format, argList);
    va_end(argList);

    terminate(TRUE);
}

/* Display error message including ‘errno‘ diagnostic, and
   terminate the process by calling _exit().

   The relationship between this function and errExit() is analogous
   to that between _exit(2) and exit(3): unlike errExit(), this
   function does not flush stdout and calls _exit(2) to terminate the
   process (rather than exit(3), which would cause exit handlers to be
   invoked).

   These differences make this function especially useful in a library
   function that creates a child process that must then terminate
   because of an error: the child must terminate without flushing
   stdio buffers that were partially filled by the caller and without
   invoking exit handlers that were established by the caller. */

void
err_exit(const char *format, ...)
{
    va_list argList;

    va_start(argList, format);
    outputError(TRUE, errno, FALSE, format, argList);
    va_end(argList);

    terminate(FALSE);
}

/* The following function does the same as errExit(), but expects
   the error number in ‘errnum‘ */

void
errExitEN(int errnum, const char *format, ...)
{
    va_list argList;

    va_start(argList, format);
    outputError(TRUE, errnum, TRUE, format, argList);
    va_end(argList);

    terminate(TRUE);
}

/* Print an error message (without an ‘errno‘ diagnostic) */

void
fatal(const char *format, ...)
{
    va_list argList;

    va_start(argList, format);
    outputError(FALSE, 0, TRUE, format, argList);
    va_end(argList);

    terminate(TRUE);
}

/* Print a command usage error message and terminate the process */

void
usageErr(const char *format, ...)
{
    va_list argList;

    fflush(stdout);           /* Flush any pending stdout */

    fprintf(stderr, "Usage: ");
    va_start(argList, format);
    vfprintf(stderr, format, argList);
    va_end(argList);

    fflush(stderr);           /* In case stderr is not line-buffered */
    exit(EXIT_FAILURE);
}

/* Diagnose an error in command-line arguments and
   terminate the process */

void
cmdLineErr(const char *format, ...)
{
    va_list argList;

    fflush(stdout);           /* Flush any pending stdout */

    fprintf(stderr, "Command-line usage error: ");
    va_start(argList, format);
    vfprintf(stderr, format, argList);
    va_end(argList);

    fflush(stderr);           /* In case stderr is not line-buffered */
    exit(EXIT_FAILURE);
}
/**************************************************************************                  Copyright (C) Michael Kerrisk, 2014.                   *
*                                                                         *
* This program is free software. You may use, modify, and redistribute it *
* under the terms of the GNU Lesser General Public License as published   *
* by the Free Software Foundation, either version 3 or (at your option)   *
* any later version. This program is distributed without any warranty.    *
* See the files COPYING.lgpl-v3 and COPYING.gpl-v3 for details.           *
\*************************************************************************/

/* error_functions.h

   Header file for error_functions.c.
*/
#ifndef ERROR_FUNCTIONS_H
#define ERROR_FUNCTIONS_H

/* Error diagnostic routines */

void errMsg(const char *format, ...);

#ifdef __GNUC__

    /* This macro stops ‘gcc -Wall‘ complaining that "control reaches
       end of non-void function" if we use the following functions to
       terminate main() or some other non-void function. */

#define NORETURN __attribute__ ((__noreturn__))
#else
#define NORETURN
#endif

void errExit(const char *format, ...) NORETURN ;

void err_exit(const char *format, ...) NORETURN ;

void errExitEN(int errnum, const char *format, ...) NORETURN ;

void fatal(const char *format, ...) NORETURN ;

void usageErr(const char *format, ...) NORETURN ;

void cmdLineErr(const char *format, ...) NORETURN ;

#endif

error proc,布布扣,bubuko.com

时间: 2024-10-25 01:25:53

error proc的相关文章

Ruby Proc 和 lambda的共同点和区别

Proc 和 lambda 的共同点: 语法类似Proc.new{|n| n**2} lambda{|n| n**2} 都可以用.call方法调用 hello_proc = Proc.new{ puts "Hello!" }hello_proc.call #Hello!hello_lambda = lambda{ puts "Hello!" }hello_lambda.call #Hello! 都可以用&关键字把各自转换为blocknums = [1,3,4

[python] python单元测试经验总结

python写单元大多数都会用到unittest和mock,测试代码覆盖率都会用到coverage,最后再用nose把所有的东西都串起来,这样每次出版本,都能把整个项目的单元测试都运行一遍. Unittest unittest就不详细介绍了,注意几点: 测试类继承unittest.TestCase 测试类.测试方法名字最好以test开头,很多工具能根据名字来自动运行,很方便 测试类里面的setUp/tearDown会在每个case执行之前/之后执行,setUpClass/tearDownClas

SQL Server2012 T-SQL基础教程--读书笔记(8 - 10章)

SQL Server2012 T-SQL基础教程--读书笔记(8 - 10章) 示例数据库:点我 CHAPTER 08 数据修改 8.1 插入数据 8.1.1 INSERT VALUES 语句 8.1.2 INSERT SELECT 语句 8.1.3 INSERT EXEC 语句 8.1.4 SELECT INTO 语句 8.1.5 BULK INSERT 语句 8.1.6 标识列属性和序列对象 8.1.6.1 标识列属性 8.1.6.2 序列对象 8.2 删除数据 8.2.1 DELETE 语

优化内核报错及解决方法

#optimizecat >>/etc/sysctl.conf<<EOF/proc/sys/net/core/rmem_default=8388608/proc/sys/net/core/rmem_max=8388608/proc/sys/net/core/wmem_default=16777216/proc/sys/net/core/wmem_max=16777216EOFsysctl -p 执行以上语句后,就报错. [[email protected] ~]# sysctl -

笔记-Microsoft SQL Server 2008技术内幕:T-SQL语言基础-10 可编程对象

关于批处理 下列语句不能在同一批处理中和其他语句同时编译:CREATE DEFAULT.CREATE FUNCTION.CREATE PROCEDURE.CREATE RULE.CREATE SCHEMA.CREATE TRIGGER及CREATE VIEW.例如,以下代码包含一个IF语句,之后在同一批处理中跟着一个CREATE VIEW语句,SQL Server将会报错: IF OBJECT_ID('Sales.MyView', 'V') IS NOT NULL DROP VIEW Sales

UNIX环境高级编程8.9竞争条件

这一节,书中的TELL_WAIT与TELL_PARENT,TELL_CHILD没有弄清楚,到底是如何实现的同步机制. // proc/tellwait1.c 8-6 #include "apue.h" static void charatatime(const char *); int main(void) { pid_t pid; if ((pid = fork()) < 0) { err_sys("fork error"); } else if (pid

Ubuntu开机显示An error occurred while mounting /proc/bus/usb 问题的解决

1.打开  /etc/fstab sudo gedit /etc/fstab       (使用vi等其他编辑器打开也可) 2.注释掉  none /proc/bus/usb usbfs devgid=125,devmode=664 0 0  一行,在前边加上  #   即可. 3.重启问题解决

Error code:1728 Cannot load from mysql.proc. The table is probably corrupted

http://bugs.mysql.com/bug.php? id=50183 原因是mysql.proc 在5.1 comment char(64) -> 5.5 comment text 导致 The difference seen in the mysql.proc table is 5.5 <   `comment` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, --- 5.1 >   `comment` char(64)

InnoDB: Error: io_setup() failed with EAGAIN after 5 attempts

在一台server中以各数据库的备份文件为数据文件启动多个MySQL实例供SQL Review使用. 之前执行一直没有问题(最多的时候有23个MySQL实例同一时候执行).后来新配置了一台server,启动其相应的实例时失败. 部分错误日志例如以下: -- 140505 16:05:59 InnoDB: Using Linux native AIO 140505 16:05:59  InnoDB: Warning: io_setup() failed with EAGAIN. Will make