Code Monkey home page Code Monkey logo

sudodev's Introduction

关于我

Code Time

Profile Views

Lines of code

🐱 我的 GitHub 数据

📦 使用了 4.5 MB GitHub 存储空间

🏆 24 个贡献,在 2024 年

🚫 不开放招聘

📜 26 个公共仓库

🔑 0 个私人仓库

我是早起的 🐤

🌞 早晨                     1154 commits        ██████░░░░░░░░░░░░░░░░░░░   24.91 % 
🌆 白天                     1477 commits        ████████░░░░░░░░░░░░░░░░░   31.89 % 
🌃 傍晚                     1661 commits        █████████░░░░░░░░░░░░░░░░   35.86 % 
🌙 晚上                     340 commits         ██░░░░░░░░░░░░░░░░░░░░░░░   07.34 % 

📅 我最有效率是在 星期一

星期一                      793 commits         ████░░░░░░░░░░░░░░░░░░░░░   17.12 % 
星期二                      784 commits         ████░░░░░░░░░░░░░░░░░░░░░   16.93 % 
星期三                      770 commits         ████░░░░░░░░░░░░░░░░░░░░░   16.62 % 
星期四                      631 commits         ███░░░░░░░░░░░░░░░░░░░░░░   13.62 % 
星期五                      555 commits         ███░░░░░░░░░░░░░░░░░░░░░░   11.98 % 
星期六                      474 commits         ███░░░░░░░░░░░░░░░░░░░░░░   10.23 % 
星期日                      625 commits         ███░░░░░░░░░░░░░░░░░░░░░░   13.49 % 

📊 本周消耗时间

🕑︎ 时区: Asia/Shanghai

💬 编程语言: 
C                        21 mins             ██████████████░░░░░░░░░░░   57.40 % 
Markdown                 9 mins              ██████░░░░░░░░░░░░░░░░░░░   25.48 % 
INI                      3 mins              ██░░░░░░░░░░░░░░░░░░░░░░░   07.99 % 
Bash                     1 min               █░░░░░░░░░░░░░░░░░░░░░░░░   04.28 % 
RPMSpec                  1 min               █░░░░░░░░░░░░░░░░░░░░░░░░   03.66 % 

🔥 编辑器: 
Vim                      38 mins             █████████████████████████   100.00 % 

💻 操作系统: 
Linux                    38 mins             █████████████████████████   100.00 % 

我最常使用 Python

Python                   5 repos             █████░░░░░░░░░░░░░░░░░░░░   19.23 % 
JavaScript               5 repos             █████░░░░░░░░░░░░░░░░░░░░   19.23 % 
C                        5 repos             █████░░░░░░░░░░░░░░░░░░░░   19.23 % 
Shell                    3 repos             ███░░░░░░░░░░░░░░░░░░░░░░   11.54 % 
Go                       1 repo              █░░░░░░░░░░░░░░░░░░░░░░░░   03.85 % 

时间线

Lines of Code chart

Last Updated on 2024-06-10 20:15:33 UTC

sudodev's People

Contributors

arondight avatar z-gu avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

sudodev's Issues

几个问题

dir->d_type 不支持所有文件系统

用readlink读/dev/disk/by-uuid/的位置取basename来和fstab里面的比较, 通过这种方式判断是否是本地设备?

下面是我的fstab

UUID=fb6bee33-feac-442c-88e3-f2b07a84d0fe /                    ext4       acl,user_xattr        1 1
UUID=a4b1cb81-d152-4da4-b221-4ea3e59d78d5 swap                 swap       defaults              0 0
UUID=bb6f4a88-f9c8-42b0-8e2b-5a1fb5f01426 /home                ext4       defaults              1 2

你程序的输出:

./sudodev add
[  1]  sda1
[  2]  sda2
[  3]  sda3
[  4]  sda5
[  5]  sda6
[  6]  sda7
[  7]  sda8
Choose a device (q to quit):  

这是插入一个U盘后的输出:

./sudodev add
[  1]  sda1
[  2]  sda2
[  3]  sda3
[  4]  sda5
[  5]  sda6
[  6]  sda7
[  7]  sda8
[  8]  sdb1
[  9]  sdb4
Choose a device (q to quit): q
quit


lsblk 
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 465.8G  0 disk 
├─sda1   8:1    0  39.2M  0 part 
├─sda2   8:2    0  11.8G  0 part 
├─sda3   8:3    0   227G  0 part 
├─sda4   8:4    0     1K  0 part 
├─sda5   8:5    0 107.4G  0 part 
├─sda6   8:6    0  38.2G  0 part /
├─sda7   8:7    0   7.6G  0 part [SWAP]
└─sda8   8:8    0  73.8G  0 part /home
sdb      8:16   1   7.5G  0 disk 
├─sdb1   8:17   1   7.5G  0 part 
└─sdb4   8:20   1 296.1M  0 part 
sr0     11:0    1  1024M  0 rom  

学姐解释下呗:blush:

segfault

以下是全过程

╭─criss@Chameleon  ~  
╰─$ git clone https://github.com/Arondight/sudodev/
Cloning into 'sudodev'...
remote: Counting objects: 179, done.
remote: Compressing objects: 100% (43/43), done.
remote: Total 179 (delta 21), reused 0 (delta 0), pack-reused 136
Receiving objects: 100% (179/179), 69.62 KiB | 0 bytes/s, done.
Resolving deltas: 100% (106/106), done.
Checking connectivity... done.
╭─criss@Chameleon  ~  
╰─$ cd sudodev 
╭─criss@Chameleon  ~/sudodev  ‹master› 
╰─$ ./build.sh &>/dev/null
╭─criss@Chameleon  ~/sudodev  ‹master› 
╰─$ cd bin 
╭─criss@Chameleon  ~/sudodev/bin  ‹master› 
╰─$ su
Password: 
Chameleon:/home/criss/sudodev/bin # rm /var/run/sudodevd.pid 
Chameleon:/home/criss/sudodev/bin # ./sudodevd 
Chameleon:/home/criss/sudodev/bin # pgrep sudodevd
Chameleon:/home/criss/sudodev/bin # date
Mon Nov  9 13:32:25 CST 2015

查看日志 journalctl -xn

Nov 09 13:32:05 Chameleon sudodevd[10960]: SIGHUP is received, reload config                                                                                                                   
Nov 09 13:32:05 Chameleon kernel: sudodevd[10960]: segfault at 0 ip 00000000004026a8 sp 00007ffecb183a70 error 4 in sudodevd[400000+7000] 

然后我就issue你了。

Conditional jump or move depends on uninitialised value(s)

I think this is not a bug but need to find out what happend.

$ sudo valgrind --leak-check=full --show-reachable=yes --trace-children=yes -v ../bin/sudodevd
==7792== Memcheck, a memory error detector
==7792== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==7792== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==7792== Command: ../bin/sudodevd
==7792== 
--7792-- Valgrind options:
--7792--    --leak-check=full
--7792--    --show-reachable=yes
--7792--    --trace-children=yes
--7792--    -v
--7792-- Contents of /proc/version:
--7792--   Linux version 4.6.2-1-ARCH (builduser@tobias) (gcc version 6.1.1 20160602 (GCC) ) #1 SMP PREEMPT Wed Jun 8 08:40:59 CEST 2016
--7792-- 
--7792-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-avx-avx2-bmi
--7792-- Page sizes: currently 4096, max supported 4096
--7792-- Valgrind library directory: /usr/lib/valgrind
--7792-- Reading syms from /home/shell_way/Repo/my/sudodev/bin/sudodevd
--7792-- Reading syms from /usr/lib/ld-2.23.so
--7792-- Reading syms from /usr/lib/valgrind/memcheck-amd64-linux
--7792--    object doesn't have a symbol table
--7792--    object doesn't have a dynamic symbol table
--7792-- Scheduler: using generic scheduler lock implementation.
--7792-- Reading suppressions file: /usr/lib/valgrind/default.supp
==7792== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-7792-by-root-on-???
==7792== embedded gdbserver: writing to   /tmp/vgdb-pipe-to-vgdb-from-7792-by-root-on-???
==7792== embedded gdbserver: shared mem   /tmp/vgdb-pipe-shared-mem-vgdb-7792-by-root-on-???
==7792== 
==7792== TO CONTROL THIS PROCESS USING vgdb (which you probably
==7792== don't want to do, unless you know exactly what you're doing,
==7792== or are doing some strange experiment):
==7792==   /usr/lib/valgrind/../../bin/vgdb --pid=7792 ...command...
==7792== 
==7792== TO DEBUG THIS PROCESS USING GDB: start GDB like this
==7792==   /path/to/gdb ../bin/sudodevd
==7792== and then give GDB the following command
==7792==   target remote | /usr/lib/valgrind/../../bin/vgdb --pid=7792
==7792== --pid is optional if only one valgrind process is running
==7792== 
--7792-- REDIR: 0x401aa70 (ld-linux-x86-64.so.2:strlen) redirected to 0x3809e171 (???)
--7792-- Reading syms from /usr/lib/valgrind/vgpreload_core-amd64-linux.so
--7792--    object doesn't have a symbol table
--7792-- Reading syms from /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so
--7792--    object doesn't have a symbol table
==7792== WARNING: new redirection conflicts with existing -- ignoring it
--7792--     old: 0x0401aa70 (strlen              ) R-> (0000.0) 0x3809e171 ???
--7792--     new: 0x0401aa70 (strlen              ) R-> (2007.0) 0x04c2dc60 strlen
--7792-- REDIR: 0x40193c0 (ld-linux-x86-64.so.2:index) redirected to 0x4c2d800 (index)
--7792-- REDIR: 0x40195e0 (ld-linux-x86-64.so.2:strcmp) redirected to 0x4c2ed10 (strcmp)
--7792-- REDIR: 0x401b810 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4c31eb0 (mempcpy)
--7792-- Reading syms from /usr/lib/libpthread-2.23.so
--7792-- Reading syms from /usr/lib/libc-2.23.so
--7792-- REDIR: 0x50d4ed0 (libc.so.6:strcasecmp) redirected to 0x4a266be (_vgnU_ifunc_wrapper)
--7792-- REDIR: 0x50d08b0 (libc.so.6:strcspn) redirected to 0x4a266be (_vgnU_ifunc_wrapper)
--7792-- REDIR: 0x50d71c0 (libc.so.6:strncasecmp) redirected to 0x4a266be (_vgnU_ifunc_wrapper)
--7792-- REDIR: 0x50d2d20 (libc.so.6:strpbrk) redirected to 0x4a266be (_vgnU_ifunc_wrapper)
--7792-- REDIR: 0x50d30b0 (libc.so.6:strspn) redirected to 0x4a266be (_vgnU_ifunc_wrapper)
--7792-- REDIR: 0x50d4620 (libc.so.6:memcpy@GLIBC_2.2.5) redirected to 0x4a266be (_vgnU_ifunc_wrapper)
--7792-- REDIR: 0x50d2a30 (libc.so.6:rindex) redirected to 0x4c2d4e0 (rindex)
==7793== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-7793-by-root-on-???
==7793== embedded gdbserver: writing to   /tmp/vgdb-pipe-to-vgdb-from-7793-by-root-on-???
==7793== embedded gdbserver: shared mem   /tmp/vgdb-pipe-shared-mem-vgdb-7793-by-root-on-???
==7793== 
==7793== TO CONTROL THIS PROCESS USING vgdb (which you probably
==7793== don't want to do, unless you know exactly what you're doing,
==7793== or are doing some strange experiment):
==7793==   /usr/lib/valgrind/../../bin/vgdb --pid=7793 ...command...
==7793== 
==7793== TO DEBUG THIS PROCESS USING GDB: start GDB like this
==7793==   /path/to/gdb ../bin/sudodevd
==7793== and then give GDB the following command
==7793==   target remote | /usr/lib/valgrind/../../bin/vgdb --pid=7793
==7793== --pid is optional if only one valgrind process is running
==7793== 
==7794== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-7794-by-root-on-???
==7794== embedded gdbserver: writing to   /tmp/vgdb-pipe-to-vgdb-from-7794-by-root-on-???
==7794== embedded gdbserver: shared mem   /tmp/vgdb-pipe-shared-mem-vgdb-7794-by-root-on-???
==7794== 
==7794== TO CONTROL THIS PROCESS USING vgdb (which you probably
==7794== don't want to do, unless you know exactly what you're doing,
==7794== or are doing some strange experiment):
==7794==   /usr/lib/valgrind/../../bin/vgdb --pid=7794 ...command...
==7794== 
==7794== TO DEBUG THIS PROCESS USING GDB: start GDB like this
==7794==   /path/to/gdb ../bin/sudodevd
==7794== and then give GDB the following command
==7794==   target remote | /usr/lib/valgrind/../../bin/vgdb --pid=7794
==7794== --pid is optional if only one valgrind process is running
==7794== 
--7794-- REDIR: 0x50db840 (libc.so.6:strchrnul) redirected to 0x4c319e0 (strchrnul)
--7792-- REDIR: 0x50cb780 (libc.so.6:free) redirected to 0x4c2bc63 (free)
--7794-- REDIR: 0x50d1110 (libc.so.6:strncat) redirected to 0x4a266be (_vgnU_ifunc_wrapper)
--7794-- REDIR: 0x50ea160 (libc.so.6:__strncat_sse2_unaligned) redirected to 0x4c2da00 (strncat)
--7793-- REDIR: 0x50cb780 (libc.so.6:free) redirected to 0x4c2bc63 (free)
==7792== 
==7792== HEAP SUMMARY:
==7792==     in use at exit: 0 bytes in 0 blocks
==7792==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==7792== 
==7792== All heap blocks were freed -- no leaks are possible
==7792== 
==7792== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
==7792== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
--7794-- REDIR: 0x50cf300 (libc.so.6:strcmp) redirected to 0x4a266be (_vgnU_ifunc_wrapper)
--7794-- REDIR: 0x50e05f0 (libc.so.6:__strcmp_sse2_unaligned) redirected to 0x4c2ebd0 (strcmp)
==7793==                                                                                                                                                                                
==7793== HEAP SUMMARY:
==7793==     in use at exit: 0 bytes in 0 blocks
==7793==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==7793== 
==7793== All heap blocks were freed -- no leaks are possible
==7793== 
==7793== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
==7793== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
--7794-- REDIR: 0x50cb180 (libc.so.6:malloc) redirected to 0x4c2ab49 (malloc)
--7794-- REDIR: 0x50d3650 (libc.so.6:__GI_strstr) redirected to 0x4c32110 (__strstr_sse2)
--7794-- REDIR: 0x50d98c0 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x4a266be (_vgnU_ifunc_wrapper)
--7794-- REDIR: 0x5179cb0 (libc.so.6:__memcpy_avx_unaligned) redirected to 0x4c2f0e0 (memcpy@@GLIBC_2.14)
--7794-- REDIR: 0x50cb820 (libc.so.6:realloc) redirected to 0x4c2ca53 (realloc)
==7794== Conditional jump or move depends on uninitialised value(s)
==7794==    at 0x403E7C: readfile (in /home/shell_way/Repo/my/sudodev/bin/sudodevd)
==7794==    by 0x403427: find (in /home/shell_way/Repo/my/sudodev/bin/sudodevd)
==7794==    by 0x401C5C: main (in /home/shell_way/Repo/my/sudodev/bin/sudodevd)
==7794== 
--7794-- REDIR: 0x50d0d50 (libc.so.6:strlen) redirected to 0x4c2dba0 (strlen)
--7794-- REDIR: 0x50cb780 (libc.so.6:free) redirected to 0x4c2bc63 (free)
--7794-- REDIR: 0x50cbb00 (libc.so.6:calloc) redirected to 0x4c2c8b1 (calloc)
--7794-- REDIR: 0x50d9940 (libc.so.6:__GI_memcpy) redirected to 0x4c2f740 (__GI_memcpy)
--7794-- REDIR: 0x50d4080 (libc.so.6:__GI_memcmp) redirected to 0x4c307d0 (__GI_memcmp)
--7794-- REDIR: 0x50db630 (libc.so.6:rawmemchr) redirected to 0x4c31a10 (rawmemchr)
--7794-- REDIR: 0x50d4880 (libc.so.6:__GI_mempcpy) redirected to 0x4c31be0 (__GI_mempcpy)
==7794== Conditional jump or move depends on uninitialised value(s)
==7794==    at 0x403E7C: readfile (in /home/shell_way/Repo/my/sudodev/bin/sudodevd)
==7794==    by 0x403427: find (in /home/shell_way/Repo/my/sudodev/bin/sudodevd)
==7794==    by 0x4048BD: enableDropInFile (in /home/shell_way/Repo/my/sudodev/bin/sudodevd)
==7794==    by 0x401C73: main (in /home/shell_way/Repo/my/sudodev/bin/sudodevd)
==7794== 
==7794== Use of uninitialised value of size 8
==7794==    at 0x403EA2: readfile (in /home/shell_way/Repo/my/sudodev/bin/sudodevd)
==7794==    by 0x403427: find (in /home/shell_way/Repo/my/sudodev/bin/sudodevd)
==7794==    by 0x4048BD: enableDropInFile (in /home/shell_way/Repo/my/sudodev/bin/sudodevd)
==7794==    by 0x401C73: main (in /home/shell_way/Repo/my/sudodev/bin/sudodevd)
==7794== 
--7794-- REDIR: 0x50d4480 (libc.so.6:__GI_memmove) redirected to 0x4c31420 (__GI_memmove)
--7794-- REDIR: 0x50d29f0 (libc.so.6:strncpy) redirected to 0x4a266be (_vgnU_ifunc_wrapper)
--7794-- REDIR: 0x50e7080 (libc.so.6:__strncpy_sse2_unaligned) redirected to 0x4c2e1b0 (__strncpy_sse2_unaligned)
==7794== Conditional jump or move depends on uninitialised value(s)
==7794==    at 0x403E7C: readfile (in /home/shell_way/Repo/my/sudodev/bin/sudodevd)
==7794==    by 0x402ECC: devs (in /home/shell_way/Repo/my/sudodev/bin/sudodevd)
==7794==    by 0x401D15: main (in /home/shell_way/Repo/my/sudodev/bin/sudodevd)
==7794== 
--7794-- REDIR: 0x50d3ac0 (libc.so.6:strstr) redirected to 0x4a266be (_vgnU_ifunc_wrapper)
--7794-- REDIR: 0x50eb0f0 (libc.so.6:__strstr_sse2_unaligned) redirected to 0x4c320a0 (strstr)
--7794-- REDIR: 0x50d4680 (libc.so.6:memset) redirected to 0x4a266be (_vgnU_ifunc_wrapper)
--7794-- REDIR: 0x519e780 (libc.so.6:__memset_avx2) redirected to 0x4c31100 (memset)

Failed to start sudodevd

● sudodevd.service - Create your special device for a none-password sudo
   Loaded: loaded (/usr/lib/systemd/system/sudodevd.service; enabled; vendor preset: disabled)
   Active: failed (Result: start-limit-hit) since 四 2016-06-09 18:54:38 CST; 7min ago
     Docs: https://github.com/Arondight/sudodev
  Process: 17413 ExecStop=/bin/kill -TERM $MAINPID (code=exited, status=1/FAILURE)
  Process: 17409 ExecStart=/usr/bin/sudodevd (code=exited, status=0/SUCCESS)
 Main PID: 17404 (code=exited, status=0/SUCCESS)

6月 09 18:54:37 this-is-a-good-pc systemd[1]: sudodevd.service: Unit entered failed state.
6月 09 18:54:37 this-is-a-good-pc systemd[1]: sudodevd.service: Failed with result 'exit-code'.
6月 09 18:54:38 this-is-a-good-pc systemd[1]: sudodevd.service: Service hold-off time over, scheduling restart.
6月 09 18:54:38 this-is-a-good-pc systemd[1]: Stopped Create your special device for a none-password sudo.
6月 09 18:54:38 this-is-a-good-pc systemd[1]: sudodevd.service: Start request repeated too quickly.
6月 09 18:54:38 this-is-a-good-pc systemd[1]: Failed to start Create your special device for a none-password sudo.
6月 09 18:54:38 this-is-a-good-pc systemd[1]: sudodevd.service: Unit entered failed state.
6月 09 18:54:38 this-is-a-good-pc systemd[1]: sudodevd.service: Failed with result 'start-limit-hit'.

执行install.sh报错

窝用的arch
窝在运行install.sh时报错
sudo sh install.sh
install.sh: 第 6 行:source: build.sh: 文件未找到
脚本改为sh build.sh install却可以正常运行
还有,以非root身份运行build会退出,这样就得重启终端。
窝等会给你pull一下

segmentation fault

sudo sudodev add                                                                                                         shell_way@this-is-a-good-pc
[  1]  sdc1
[  2]  sdc2
Choose a device (q to quit): 2
Adding device ...   [1]    14417 segmentation fault  sudo sudodev add

Ref #12

内存泄露

没有插入外部设备, 执行 valgrind --leak-check=full --show-leak-kinds=all ./sudodev add
部分输出:

==7931== HEAP SUMMARY:
==7931==     in use at exit: 8,200 bytes in 2 blocks
==7931==   total heap usage: 106 allocs, 104 frees, 126,457 bytes allocated
==7931== 
==7931== 8 bytes in 1 blocks are still reachable in loss record 1 of 2
==7931==    at 0x4C29110: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==7931==    by 0x4017D5: add (sudodev.c:193)
==7931==    by 0x402739: attempt (sudodev.c:559)
==7931==    by 0x40283F: main (sudodev.c:604)
==7931== 
==7931== 8,192 bytes in 1 blocks are definitely lost in loss record 2 of 2
==7931==    at 0x4C29110: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==7931==    by 0x403103: devs (devs.c:243)
==7931==    by 0x40171E: add (sudodev.c:173)
==7931==    by 0x402739: attempt (sudodev.c:559)
==7931==    by 0x40283F: main (sudodev.c:604)
==7931== 
==7931== LEAK SUMMARY:
==7931==    definitely lost: 8,192 bytes in 1 blocks
==7931==    indirectly lost: 0 bytes in 0 blocks
==7931==      possibly lost: 0 bytes in 0 blocks
==7931==    still reachable: 8 bytes in 1 blocks
==7931==         suppressed: 0 bytes in 0 blocks
==7931== 
==7931== For counts of detected and suppressed errors, rerun with: -v
==7931== Use --track-origins=yes to see where uninitialised values come from
==7931== ERROR SUMMARY: 12 errors from 4 contexts (suppressed: 0 from 0)

sudodev.c中的add()函数中有一段代码

if (count < 1)
{
    say (mode, MSG_W, "No available device found\n");
    return 1;
} 

建议将return 1 改为 goto CLEAN

这是feature还是bug

我尝试用C++按照我的理解写一遍,发现我的是这样:
按照uuid输出

./a.out add
Scaning avaliable devices...
The following choices are avaliable
[q]. quit
[0]. 4E36250D3624F79B
[1]. 9C941A5B941A37EA
[2]. fd223770-d482-3d1e-9963-8e7e6c659a68
[3]. 0229-150D
[4]. 807ca61d-328c-3625-a54f-bb18bf62f086
Please enter a choice: q

按照分区输出

./a.out add
Scaning avaliable devices...
The following choices are avaliable
[q]. quit
[0]. sda5
[1]. sda4
[2]. sda2
[3]. sda1
[4]. sda3
Please enter a choice: q

这两个输出是同一个设备。
由于我的机器有两块硬盘,系统所在硬盘是/dev/sdb 所以通过fstab过滤后剩下的就是/dev/sda了。

但是学姐的是这样:

./sudodev add
uuid[0] = (null)
uuid[1] = (null)
uuid[2] = (null)
uuid[3] = (null)
uuid[4] = 4E36250D3624F79B
uuid[5] = 9C941A5B941A37EA
uuid[6] = fd223770-d482-3d1e-9963-8e7e6c659a68
uuid[7] = 0229-150D
uuid[8] = (null)
uuid[9] = 807ca61d-328c-3625-a54f-bb18bf62f086
uuid[10] = (null)
No available device found
attempt failed

修改的代码, devs.c
modified1

上面输出的(null)就是已经过滤掉的/dev/sdbx, 但是在sudodev.c里面,有这样的代码

for (index = 0; list[index]; ++index);
  devicesLen = index;

  if (!(devices = (device_t **)malloc ((devicesLen + 1) * sizeof (device_t *))))
    {
      say (mode, MSG_E, "malloc failed: %s\n", strerror (errno));
      abort ();
    }
  memset (devices, 0, (devicesLen + 1) * sizeof (device_t *));

  for (index = 0, count = 0; list[index]; ++index)
    {
      snprintf (path, MAXPATHLEN, "%s/%s", interface, list[index]);

    ...

这个文件中的count 没有初始化, 在以上for()中自加,但是由于list[index]为null不会进入循环
modified2

所以,学姐, 这是feature还是bug啊? 另外的那块硬盘算是外部设备吗?

Invalid read/write of size 1

This happend when delete the last device.

$ sudo sudodev del
[  1]  sdc2
Choose a device (q to quit): 1
Deleting device ... done
Reloading config ...    done

And here is log of valgrind.

==9978==                                                                                                                                                                                
==9978== HEAP SUMMARY:
==9978==     in use at exit: 0 bytes in 0 blocks
==9978==   total heap usage: 3,880 allocs, 3,880 frees, 7,936,335 bytes allocated
==9978== 
==9978== All heap blocks were freed -- no leaks are possible
==9978== 
==9978== ERROR SUMMARY: 4 errors from 2 contexts (suppressed: 0 from 0)
==9978== 
==9978== 2 errors in context 1 of 2:
==9978== Invalid read of size 1
==9978==    at 0x403EA0: readfile (in /home/shell_way/Repo/my/sudodev/bin/sudodevd)
==9978==    by 0x402444: sighupHandler (in /home/shell_way/Repo/my/sudodev/bin/sudodevd)
==9978==    by 0x4E46EFF: ??? (in /usr/lib/libpthread-2.23.so)
==9978==    by 0x510A4DF: __nanosleep_nocancel (in /usr/lib/libc-2.23.so)
==9978==    by 0x510A449: sleep (in /usr/lib/libc-2.23.so)
==9978==    by 0x401F7F: main (in /home/shell_way/Repo/my/sudodev/bin/sudodevd)
==9978==  Address 0x582640f is 1 bytes before a block of size 1 alloc'd
==9978==    at 0x4C2CB1D: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9978==    by 0x403E7A: readfile (in /home/shell_way/Repo/my/sudodev/bin/sudodevd)
==9978==    by 0x402444: sighupHandler (in /home/shell_way/Repo/my/sudodev/bin/sudodevd)
==9978==    by 0x4E46EFF: ??? (in /usr/lib/libpthread-2.23.so)
==9978==    by 0x510A4DF: __nanosleep_nocancel (in /usr/lib/libc-2.23.so)
==9978==    by 0x510A449: sleep (in /usr/lib/libc-2.23.so)
==9978==    by 0x401F7F: main (in /home/shell_way/Repo/my/sudodev/bin/sudodevd)
==9978== 
==9978== 
==9978== 2 errors in context 2 of 2:
==9978== Invalid write of size 1
==9978==    at 0x4C31125: memset (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9978==    by 0x403E9F: readfile (in /home/shell_way/Repo/my/sudodev/bin/sudodevd)
==9978==    by 0x402444: sighupHandler (in /home/shell_way/Repo/my/sudodev/bin/sudodevd)
==9978==    by 0x4E46EFF: ??? (in /usr/lib/libpthread-2.23.so)
==9978==    by 0x510A4DF: __nanosleep_nocancel (in /usr/lib/libc-2.23.so)
==9978==    by 0x510A449: sleep (in /usr/lib/libc-2.23.so)
==9978==    by 0x401F7F: main (in /home/shell_way/Repo/my/sudodev/bin/sudodevd)
==9978==  Address 0x582640f is 1 bytes before a block of size 1 alloc'd
==9978==    at 0x4C2CB1D: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9978==    by 0x403E7A: readfile (in /home/shell_way/Repo/my/sudodev/bin/sudodevd)
==9978==    by 0x402444: sighupHandler (in /home/shell_way/Repo/my/sudodev/bin/sudodevd)
==9978==    by 0x4E46EFF: ??? (in /usr/lib/libpthread-2.23.so)
==9978==    by 0x510A4DF: __nanosleep_nocancel (in /usr/lib/libc-2.23.so)
==9978==    by 0x510A449: sleep (in /usr/lib/libc-2.23.so)
==9978==    by 0x401F7F: main (in /home/shell_way/Repo/my/sudodev/bin/sudodevd)
==9978== 
==9978== ERROR SUMMARY: 4 errors from 2 contexts (suppressed: 0 from 0)

Automated installation

  • Automatic processing files under init directory
    • systemd
    • Upstart
    • SysVinit
    • BSDinit
  • Add current user to sudodev group

权限问题

我发现你这两个程序都需要root权限才能运行啊。。。

设计的初衷就是这样, 还是想

setuid(0);

然后chown root:root xxx + chmod u+s xxx ??

另外,我用C++写的已经写好了,不知道对不对,学姐帮我看看行吗?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.