linux - ntpdate 的退出代码是什么意思?

标签 linux ntp

当没有事件的互联网连接时在 Linux 上运行 ntpdate 程序会在控制台中显示此消息:

Exiting, name server cannot be used: Temporary failure in name resolution

程序的退出代码是 1 就是这种情况。但是我找不到退出代码的真正含义,可以肯定地说退出代码 1 总是与上述错误相对应吗?

看看the docs对我没有帮助,它说了以下内容:

ntpdate's exit status is zero if it finds a server and updates the clock, and nonzero otherwise.

谁能给我一份所有可能的退出代码及其含义的列表?

谢谢!

最佳答案

查看 Source Code of the ntpdate program 后我想我可以回答我自己的问题。

不,退出代码 1 并不总是与错误 Exiting, name server cannot be used: Temporary failure in name resolution 相关。

在源码中搜索exit(1),找到了20个exit code为1的情况。

对于任何感兴趣的人,导致 Exiting, name server cannot use: Temporary failure in name resolution 错误消息的代码片段:

error = getaddrinfo(serv, service, &hints, &addrResult);
if (error != 0) {
    /* Conduct more refined error analysis */
    if (error == EAI_FAIL || error == EAI_AGAIN){
        /* Name server is unusable. Exit after failing on the
           first server, in order to shorten the timeout caused
           by waiting for resolution of several servers */
        fprintf(stderr, "Exiting, name server cannot be used: %s (%d)",
            gai_strerror(error), error);
        msyslog(LOG_ERR, "name server cannot be used: %s (%d)",
            gai_strerror(error), error);
        exit(1);
    }
    fprintf(stderr, "Error resolving %s: %s (%d)\n", serv,
        gai_strerror(error), error);
    msyslog(LOG_ERR, "Can't find host %s: %s (%d)", serv,
        gai_strerror(error), error);
    return;
}

关于linux - ntpdate 的退出代码是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44282282/

相关文章:

ntp - NTP 尝试同步的 'frequency difference' 是什么?

c - 如何在另一个线程完成后执行另一个线程?

NTP 服务器的 php 验证

c++ - 使用内存区域作为堆栈空间?

linux - 在 Linux 中对文件具有可执行权限有哪些安全风险?

windows - 同步通过 LAN 电缆连接的两台 Windows 7 计算机之间的时间

linux - 无法让 NTP 交叉编译到 ARM

datetime - Ubuntu shell 脚本 : Get and echo time from ntp server without synchronization

linux - 如何使用 .sh 文件提取帧并设置每秒帧数

linux - 是否加载了操作系统级别的闪存驱动程序?