当前位置:  技术问答>linux和unix

问一个很常见的问题

    来源: 互联网  发布时间:2016-08-11

    本文导语:  我的嵌入式系统中没有write命令也没有talk命令,我想找个源码包交叉编译了,到死活找不到。 有哪位大侠知道,write、talk等可执行文件到底怎么来的? | http://src.opensolaris.org/source/xref/onnv/onnv-...

我的嵌入式系统中没有write命令也没有talk命令,我想找个源码包交叉编译了,到死活找不到。

有哪位大侠知道,write、talk等可执行文件到底怎么来的?

|
http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/cmd/cmd-inet/usr.bin/talk/

|
先看看该命令属于哪个包 应该能找到
#which write
/usr/bin/write
#rpm -qf /usr/bin/write
util-linux-2.13-0.52.el5_4.1

write的源码应该在util-linux源码里

|
我在下面这里下载了util-linux 找到了write的源码util-linux-2.12j/misc-utils/write.c
http://www.kernel.org/pub/linux/utils/util-linux/

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include "pathnames.h"
#include "carefulputc.h"
#include "nls.h"

void search_utmp(char *, char *, char *, uid_t);
void do_write(char *, char *, uid_t);
void wr_fputs(char *);
static void done(int);
int term_chk(char *, int *, time_t *, int);
int utmp_chk(char *, char *);

int
main(int argc, char **argv) {
        time_t atime;
        uid_t myuid;
        int msgsok, myttyfd;
        char tty[MAXPATHLEN], *mytty;

        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);

        /* check that sender has write enabled */
        if (isatty(fileno(stdin)))
                myttyfd = fileno(stdin);
        else if (isatty(fileno(stdout)))
                myttyfd = fileno(stdout);
        else if (isatty(fileno(stderr)))
                myttyfd = fileno(stderr);
        else {
                myttyfd = -1;
        }
        if (myttyfd != -1) {
          if (!(mytty = ttyname(myttyfd))) {
                (void)fprintf(stderr, _("write: can't find your tty's namen"));
                exit(1);
          }
          /* We may have /dev/ttyN but also /dev/pts/xx.
             Below, term_chk() will put "/dev/" in front, so remove that part. */
          if (!strncmp(mytty, "/dev/", 5))
                mytty += 5;
          if (term_chk(mytty, &msgsok, &atime, 1))
                exit(1);
          if (!msgsok) {
                (void)fprintf(stderr,
                    _("write: you have write permission turned off.n"));
                exit(1);
          }

        } else {
            mytty = "";
        }

        myuid = getuid();

        /* check args */
        switch (argc) {
        case 2:
                search_utmp(argv[1], tty, mytty, myuid);
                do_write(tty, mytty, myuid);
                break;
        case 3:
                if (!strncmp(argv[2], "/dev/", 5))
                        argv[2] += 5;
                if (utmp_chk(argv[1], argv[2])) {
                        (void)fprintf(stderr,
                            _("write: %s is not logged in on %s.n"),
                            argv[1], argv[2]);
                        exit(1);
                }
                if (term_chk(argv[2], &msgsok, &atime, 1))
                        exit(1);
                if (myuid && !msgsok) {
                        (void)fprintf(stderr,
                            _("write: %s has messages disabled on %sn"),
                            argv[1], argv[2]);
                        exit(1);
                }
                do_write(argv[2], mytty, myuid);
                break;
        default:
                (void)fprintf(stderr, _("usage: write user [tty]n"));
                exit(1);
        }
        done(0);
        /* NOTREACHED */
        return 0;
}


/*
 * utmp_chk - checks that the given user is actually logged in on
 *     the given tty
 */
int utmp_chk(char *user, char *tty)

{
        struct utmp u;
        struct utmp *uptr;
        int res = 1;

        utmpname(_PATH_UTMP);
        setutent();

        while ((uptr = getutent())) {
                memcpy(&u, uptr, sizeof(u));
                if (strncmp(user, u.ut_name, sizeof(u.ut_name)) == 0 &&
                    strncmp(tty, u.ut_line, sizeof(u.ut_line)) == 0) {
                        res = 0;
                        break;
                }
        }

        endutent();
        return(res);
}

void search_utmp(char *user, char *tty, char *mytty, uid_t myuid)

{
        struct utmp u;
        struct utmp *uptr;
        time_t bestatime, atime;
        int nloggedttys, nttys, msgsok, user_is_me;
        char atty[sizeof(u.ut_line) + 1];

        utmpname(_PATH_UTMP);
        setutent();

        nloggedttys = nttys = 0;
        bestatime = 0;
        user_is_me = 0;
        while ((uptr = getutent())) {
                memcpy(&u, uptr, sizeof(u));
                if (strncmp(user, u.ut_name, sizeof(u.ut_name)) == 0) {
                        ++nloggedttys;
                        (void)strncpy(atty, u.ut_line, sizeof(u.ut_line));
                        atty[sizeof(u.ut_line)] = '';
                        if (term_chk(atty, &msgsok, &atime, 0))
                                continue;       /* bad term? skip */
                        if (myuid && !msgsok)
                                continue;       /* skip ttys with msgs off */
                        if (strcmp(atty, mytty) == 0) {
                                user_is_me = 1;
                                continue;       /* don't write to yourself */
                        }
                        if (u.ut_type != USER_PROCESS)
                                continue;       /* it's not a valid entry */
                        ++nttys;
                        if (atime > bestatime) {
                                bestatime = atime;
                                (void)strcpy(tty, atty);
                        }
                }
        }

        endutent();
        if (nloggedttys == 0) {
                (void)fprintf(stderr, _("write: %s is not logged inn"), user);
                exit(1);
        }
        if (nttys == 0) {
                if (user_is_me) {               /* ok, so write to yourself! */
                        (void)strcpy(tty, mytty);
                        return;
                }
                (void)fprintf(stderr,
                    _("write: %s has messages disabledn"), user);
                exit(1);
        } else if (nttys > 1) {
                (void)fprintf(stderr,
                    _("write: %s is logged in more than once; writing to %sn"),
                    user, tty);
        }
}

/*
 * term_chk - check that a terminal exists, and get the message bit
 *     and the access time
 */
int term_chk(char *tty, int *msgsokP, time_t *atimeP, int showerror)

{
        struct stat s;
        char path[MAXPATHLEN];

        if (strlen(tty) + 6 > sizeof(path))
                return(1);
        (void)sprintf(path, "/dev/%s", tty);
        if (stat(path, &s) > 3)) != 0;  /* group write bit */
        *atimeP = s.st_atime;
        return(0);
}

/*
 * do_write - actually make the connection
 */
void do_write(char *tty, char *mytty, uid_t myuid) {
        char *login, *pwuid, *nows;
        struct passwd *pwd;
        time_t now;
        char path[MAXPATHLEN], host[MAXHOSTNAMELEN], line[512];

        /* Determine our login name(s) before the we reopen() stdout */
        if ((pwd = getpwuid(myuid)) != NULL)
                pwuid = pwd->pw_name;
        else
                pwuid = "???";
        if ((login = getlogin()) == NULL)
                login = pwuid;

        if (strlen(tty) + 6 > sizeof(path))
                exit(1);
        (void)sprintf(path, "/dev/%s", tty);
        if ((freopen(path, "w", stdout)) == NULL) {
                (void)fprintf(stderr, "write: %s: %sn",
                              path, strerror(errno));
                exit(1);
        }

        (void)signal(SIGINT, done);
        (void)signal(SIGHUP, done);

        /* print greeting */
        if (gethostname(host, sizeof(host)) 

    
 
 

您可能感兴趣的文章:

  • 常见问题常见问题 搜索搜索 团队团队 个人资料个人资料 您没有新的站内信件您没有新的站内信件 注销 [ tnt_bomb ]注销 [ tnt_b
  • 菜鸟急问:一个编译出错的问题(常见的吧)
  • 有一常见问题不解,请大家聊聊!
  • 一个很常见的关于时间的问题。马上结帐!
  • 一个常见的命令行问题
  • 问一个gdb的常见问题
  • UNIX 常见问题
  • 最常见的问题:哪里有Oracle7.3 for sco5.0.5的下载?
  • 编程语言 iis7站长之家
  • web标准常见问题集合第1/2页
  • Oracle插入日期数据常见的2个问题和解决方法
  • shell常见问题
  • 关于客户端给服务器发数据的一个比较常见的问题!
  • 高手请进:我觉得是一个很常见的问题,怎么就没人能解决呢?
  • Oracle 10G安装中一些常见问题解决
  • ORACLE数据库应用开发常见问题及排除
  • Oracle Index 的三个常见问题
  • web标准常见问题集合2
  • MySQL 一次执行多条语句的实现及常见问题
  • 标准布局常见问题及解决办法
  •  
    本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
    本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐
  • linux下nm命令(显示可执行文件的符号信息)介绍以及常见nm命令用法举例
  • JSP常见的三个编译指令page、include、taglib
  • 安装hadoop时出现内存不够及其它一些常见的hadoop错误解决办法
  • 请问Linux下面有哪些常见的文件后缀名呢?
  • linux/centos安装nginx常见错误及解决办法
  • CSS中几种常见的注释
  • c++模板(template)常见用法代码实例
  • 字符不会撑大表格的常见css样式
  • mysql jdbc连接mysql数据库步骤及常见参数详解
  • mysql常见错误集锦
  • 几种常见攻击的正则表达式
  • ./congfigure的时候出错了,很常见的错误..怎么解啊..
  • 为什么常见的bbs用户的登陆名必须为英文,而不用中文?
  • SQl 语句(常见)
  • 请问各位高手,市面上常见的 SCO UNIX、FreeBSD、RedHat Linux 这几种操作系统中哪一种在易用性、稳定性、发展前景等方面更具优势?
  • Linux下Oracle常见安装错误总结及参考案例
  • Linux Shell 常见的命令行格式简明总结
  • C#(4.0)不常见的语法
  • SQL Server导入导出数据时最常见的一个错误解决方法
  • C++位操作的常见用法小结
  • 有关于PHP中常见数据类型的汇总分享


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3