确定原件退出状态code [英] Determine Original Exit Status Code

查看:107
本文介绍了确定原件退出状态code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个软件基准我维护,有150个声明S $ P $垫之间进行各种C的应用程序,使要么另一种Linux命令拨打电话(例如:室射频... )或使用自定义应用程序状态=系统(CMD)/ 256 。当任一被调用时,状态code无论从Linux命令或自定义应用程序是由 256 分返回。这样,当状态code大于0,我们知道有问题。然而,软件代码的编写方式,它并不总是记录哪些命令或应用程序返回的状态code。因此,如果状态code是说32768,当除以256,报告的状态code是的 128

In a software baseline I am maintaining, there are 150 statements spread out amongst various C applications that make a call to either another Linux command (e.g. rm -rf ...) or custom application using status = system(cmd)/256. When either is called, the status code returned from either the Linux command or custom application is divided by 256. So that when the status code is greater than 0, we know there was a problem. However, the way the software was written, it doesn't always log what command or application returned the status code. So that if the status code was say 32768, when divided by 256, the status code reported is 128.

该软件是旧的,虽然我可以进行更改,如有被称为所谓的命令或应用程序报告其原有状态code别处这将是很好。

The software is old and while I could make changes, it would be nice if any of the commands called or applications called reported their original status code elsewhere.

有没有一种方法来确定一个标准的Linux日志文件中的原始状态code和它返回它的应用程序?

Is there a way to determine the original status code in a standard Linux log file and the application which returned it?

推荐答案

如何写一个包装

下面就如何运用各地的libc功能系统()

创建一个名为新模块(翻译单元) system_wrapper.c 像这样:

Create a new module (translation units) called system_wrapper.c like so:

system_wrapper.h

#ifndef _SYSTEM_WRAPPER
#define _SYSTEM_WRAPPER

#define system(cmd) system_wrapper(cmd)

int system_wrapper(const char *);

#endif

模块 system_wrapper.c

#include <stdlib.h> /* to prototype the original function, that is libc's system() */
#include "system_wrapper.h"

#undef system

int system_wrapper(const char * cmd)
{
  int result = system(cmd);

  /* Log result here. */

  return result;
}

这行添加到使用 system()的所有模块

#include "system_wrapper.h"

这篇关于确定原件退出状态code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆