Linux API/linux2021. 4. 5. 10:53

빌드해서 올리는데 파일이 있는데 없다고?!?!

혹시나 해서 보는데 target에 file도 없어 ㅠㅠㅠㅠ 아놔 -_-

아무튼 

파일이 없는건

zynq> ./test
-sh: ./test: not found

zynq> ls -al /lib/ld-
ld-2.13.so     ld-linux.so.3

zynq> ls -al /lib/ld-linux.so.3
lrwxrwxrwx    1 root     root            10 Nov 27  2012 /lib/ld-linux.so.3 -> ld-2.13.so

zynq> ./test
FATAL: kernel too old
Aborted

 

/lib/ld-linux-armhf.so.3 와 /lib/ld-linux.so 의 차이 -_-

아니 저정도면 실행시에 링크파일이 없다고 에러나와줘야지 ㅠㅠ

왜 자기 자신이 없다고 에러가 나는게야!!

$ file test
test: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 4.9.0, with debug_info, not stripped

 

아무튼 빡쳐서(!) static 링크해서 빌드하고 실행했더니

$ file test
test: ELF 32-bit LSB executable, ARM, EABI5 version 1 (GNU/Linux), statically linked, for GNU/Linux 4.9.0, with debug_info, not stripped

 

야이!!!

zynq> ./test
FATAL: kernel too old
Aborted

 

에라이 걍 컴파일러 바꿔 -_-

[링크 : https://ggpapa.tistory.com/36]

[링크 : https://blog.naver.com/calb30095/221005114736]

'Linux API > linux' 카테고리의 다른 글

linux gpio interrupt poll?  (0) 2021.05.04
Floating point exception  (0) 2021.04.05
spi 통신 예제(linux)  (0) 2021.01.28
linux USB bulk 통신  (0) 2020.10.21
linux open() 과 8진법  (0) 2020.09.28
Posted by 구차니
Linux API2021. 2. 17. 12:18

사용 자체는 간단하다.

그런데 dmesg로 보는 법을 모르겠네? (서로 다른건가?)

(/var/log/message에 추가는 된다. 해당 파일은 ASCII TEXT)

 

#include <syslog.h>

int main(int argc, char **argv)
{
    syslog(LOG_INFO|LOG_LOCAL0, "hello world\n");
}

[링크 : https://www.joinc.co.kr/w/Site/system_programing/Unix_Env/syslog_1]

'Linux API' 카테고리의 다른 글

kms - Kernel Mode Setting  (0) 2022.07.14
libescp  (0) 2019.01.03
cups api  (0) 2018.12.20
system wait stdout  (0) 2018.10.22
ncurse  (0) 2015.04.27
Posted by 구차니
Linux API/linux2021. 1. 28. 13:59

쓸일이 곧 생길게야.... (동공지진)

 

[링크 : https://github.com/torvalds/linux/blob/master/tools/spi/spidev_test.c]

+ 2021.02.08

 

It's easy to be confused here, and the vendor documentation you'll
find isn't necessarily helpful.  The four modes combine two mode bits:

 - CPOL indicates the initial clock polarity.  CPOL=0 means the
   clock starts low, so the first (leading) edge is rising, and
   the second (trailing) edge is falling.  CPOL=1 means the clock
   starts high, so the first (leading) edge is falling.

 - CPHA indicates the clock phase used to sample data; CPHA=0 says
   sample on the leading edge, CPHA=1 means the trailing edge.

   Since the signal needs to stablize before it's sampled, CPHA=0
   implies that its data is written half a clock before the first
   clock edge.  The chipselect may have made it become available.

[링크 : https://www.kernel.org/doc/Documentation/spi/spi-summary]

Posted by 구차니
Linux API/linux2020. 10. 21. 11:50

 

 

[링크 : https://stackoverflow.com/questions/15308770/read-usb-bulk-message-on-linux]

Posted by 구차니
Linux API/network2020. 9. 29. 14:10

 

 

[링크 : https://www.joinc.co.kr/w/Site/Network_Programing/Documents/Sockettimeout]

[링크 : https://blog.cloudflare.com/ko/when-tcp-sockets-refuse-to-die-ko/]

'Linux API > network' 카테고리의 다른 글

linux tcp server listen accept connect  (0) 2022.05.11
ssl socket 예제  (0) 2022.03.25
UDS (Unix Domain Socket)  (0) 2020.09.01
raw socker과 promiscous mode  (0) 2019.07.03
리눅스 UDP 소켓  (0) 2019.05.24
Posted by 구차니
Linux API/linux2020. 9. 28. 17:54

많이 쓰지 않다 보니 잊고 있었는데

open() 시스템 콜 사용에서 퍼미션 설정시 0644라고 해야지 644로 하면 이상한 퍼미션으로 생성된다.

원인을 찾다보니.. 0644 라고 써야 할걸 귀찮아서(?!) 644라고 썼더니 오작동 한 것 같은데

16진수가 아니라 굳이 8진법을 쓰는 이유는

rwx로 조합되는 것이 2^3 = 8 이기 때문 이려나?

 

새삼 이런데서 8진법으로 표기한다는게 신기하네..

 

--w----r-T

아무튼 644로 표기하면 위의 희한한 퍼미션으로 생성된다.

T니까.. stikcy bit고.. 이거 1000(8) 일텐데

 

644(10) = 1204(8) = 284(16)

더럽게(!) 우연히 1000(8)이 들어가 버렸네?

 

 

[링크 : https://blog.naver.com/tipsware/221498204578]

'Linux API > linux' 카테고리의 다른 글

spi 통신 예제(linux)  (0) 2021.01.28
linux USB bulk 통신  (0) 2020.10.21
open with O_CREAT or O_TMPFILE in second argument needs 3 arguments  (0) 2020.09.28
open() read() write() close()를 이용한 cp 예제  (0) 2020.09.28
fopen64  (0) 2019.06.24
Posted by 구차니
Linux API/linux2020. 9. 28. 17:43

빌드하다 보니 이상한 에러 발생

 

error: call to ‘__open_missing_mode’ declared with attribute error: open with O_CREAT or O_TMPFILE in second argument needs 3 arguments

 

원인은 open() 의 인자가 2개에서 3개로 늘어서 그렇다는데

vscode 에서 따라가서 봐도 인자는 2개 이상이면 문제가 없어야 하는데... 머지?

__fortify_function int

open (const char *__path, int __oflag, ...)

{

if (__va_arg_pack_len () > 1 __open_too_many_args ();

 

if (__builtin_constant_p (__oflag))

{

        if (__OPEN_NEEDS_MODE (__oflag) && __va_arg_pack_len () < 1)

        {

                __open_missing_mode ();

                return __open_2 (__path, __oflag);

        }

        return __open_alias (__path, __oflag, __va_arg_pack ());

}

 

if (__va_arg_pack_len () < 1) return __open_2 (__path, __oflag);

 

return __open_alias (__path, __oflag, __va_arg_pack ());

}

 

일단은 추적을 해보니 O_CREAT가 0이 아니거나 O_TMP_FILE이 설정되어 있을 경우

/* Detect if open needs mode as a third argument (or for openat as a fourth

argument). */

#ifdef __O_TMPFILE

# define __OPEN_NEEDS_MODE(oflag) \

(((oflag) & O_CREAT) != 0 || ((oflag) & __O_TMPFILE) == __O_TMPFILE)

#else

# define __OPEN_NEEDS_MODE(oflag) (((oflag) & O_CREAT) != 0)

#endif

 

그리고 인자가 1보다 작을 경우(즉, 퍼미션 이 없으면)

/* GCC 4.3 and above allow passing all anonymous arguments of an

__extern_always_inline function to some other vararg function. */

#if __GNUC_PREREQ (4,3)

# define __va_arg_pack() __builtin_va_arg_pack ()

# define __va_arg_pack_len() __builtin_va_arg_pack_len ()

#endif

 

아래를 수행해야 하는데 __open_missing_mode()는 따라가지지 않고

원래대로라면 __open_2(__path, __oflag) 으로 연결되어야 하는데 왜 에러가 난 걸까?

                __open_missing_mode ();

                return __open_2 (__path, __oflag);

[링크 : https://damduc.tistory.com/316]

 

+

/usr/include$ grep -rni "__errordecl" ./
./x86_64-linux-gnu/sys/cdefs.h:125:# define __errordecl(name, msg) \

별거 아닌.. 에러문 출력하는 선언문 인듯 한데..

# define __errordecl(name, msg) \
  extern void name (void) __attribute__((__error__ (msg)))
#else
# define __warndecl(name, msg) extern void name (void)
# define __warnattr(msg)
# define __errordecl(name, msg) extern void name (void)
#endif

 

정리를 하자면 O_CREAT, O_TMPFILE이 존재할 경우

컴파일 단계에서 __open_missing_mode (); 에 도달시 에러를 내고

그 다음 return으로 도달하지 못한다. 그리고 해당 항목은 GCC 4.3 이후 버전에서

인자를 확인하도록 추가되면서 영향을 받았다. 라고 해석을 해야 할 듯?

 

4.3 이후에 추가된 버그라고 봐야 하나?

 

if (__builtin_constant_p (__oflag))

{

        if (__OPEN_NEEDS_MODE (__oflag) && __va_arg_pack_len () < 1)

        {

                __open_missing_mode ();

                return __open_2 (__path, __oflag);

        }

        return __open_alias (__path, __oflag, __va_arg_pack ());

}

'Linux API > linux' 카테고리의 다른 글

linux USB bulk 통신  (0) 2020.10.21
linux open() 과 8진법  (0) 2020.09.28
open() read() write() close()를 이용한 cp 예제  (0) 2020.09.28
fopen64  (0) 2019.06.24
ubuntu iio rotate key 찾기 또 실패  (0) 2019.05.27
Posted by 구차니
Linux API/linux2020. 9. 28. 16:23

예제 보고 대충 따라서 만들어 봄

stdio.h를 했더니 fopen이랑 추천해주고 있어서 부랴부랴 찾아보니 unistd.h를 쓰라네?

cp.c:18:9: warning: implicit declaration of function ‘read’; did you mean ‘fread’? [-Wimplicit-function-declaration]
   len = read(fd_src, buff, BUFF_LEN);
         ^~~~
         fread
cp.c:20:4: warning: implicit declaration of function ‘write’; did you mean ‘fwrite’? [-Wimplicit-function-declaration]
    write(fd_dst, buff, len);
    ^~~~~
    fwrite
cp.c:25:2: warning: implicit declaration of function ‘close’; did you mean ‘pclose’? [-Wimplicit-function-declaration]
  close(fd_src);
  ^~~~~
  pclose

 

예외처리 하나도 없이 인자만 받아서 복사하는 cp 명령의 마이너 버전 코드.

#include <unistd.h>
#include <fcntl.h>

#define BUFF_LEN 4096

int main(int argc, char** argv)
{
        int fd_src = 0;
        int fd_dst = 0;
        int len = 0;
        char buff[BUFF_LEN];

        fd_src = open(argv[1], O_RDONLY);
        fd_dst = open(argv[2], O_CREAT | O_TRUNC | O_RDWR);

        while(1)
        {
                len = read(fd_src, buff, BUFF_LEN);
                if(len > 0)
                        write(fd_dst, buff, len);
                else
                        break;
        }

        close(fd_src);
        close(fd_dst);

}

 

[링크 : https://reakwon.tistory.com/39]

[링크 : https://linux.die.net/man/3/open]

[링크 : https://linux.die.net/man/2/close]

 

 

fstat으로 파일 길이 알아내기

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>

#include <sys/types.h>
#include <sys/stat.h>

#define BUFF_LEN 4096

int main(int argc, char** argv)
{
	int fd_src = 0;
	int fd_dst = 0;
	int len = 0;
	char buff[BUFF_LEN];
	struct stat statbuf;

	fd_src = open(argv[1], O_RDONLY);
	fd_dst = open(argv[2], O_CREAT | O_TRUNC | O_RDWR);

	fstat(fd_src, &statbuf);
	printf("filename : [%s], length [%ld]\n", argv[1], statbuf.st_size);

	while(1)
	{
		len = read(fd_src, buff, BUFF_LEN);
		if(len > 0)
			write(fd_dst, buff, len);
		else
			break;
	}

	close(fd_src);
	close(fd_dst);

}

 

[링크 : https://man7.org/linux/man-pages/man2/stat.2.html]

'Linux API > linux' 카테고리의 다른 글

linux open() 과 8진법  (0) 2020.09.28
open with O_CREAT or O_TMPFILE in second argument needs 3 arguments  (0) 2020.09.28
fopen64  (0) 2019.06.24
ubuntu iio rotate key 찾기 또 실패  (0) 2019.05.27
전원버튼 IRQ 발생 관련  (0) 2018.04.23
Posted by 구차니
Linux API/network2020. 9. 1. 17:39

 

 

[링크 : https://blog.naver.com/jaelong191/221304232639]

[링크 : https://www.joinc.co.kr/w/Site/system_programing/IPC/Unix_Domain_Socket]

[링크 : https://en.wikipedia.org/wiki/Unix_domain_socket]

'Linux API > network' 카테고리의 다른 글

ssl socket 예제  (0) 2022.03.25
TCP timeout  (0) 2020.09.29
raw socker과 promiscous mode  (0) 2019.07.03
리눅스 UDP 소켓  (0) 2019.05.24
리눅스 TCP 소켓  (0) 2019.05.24
Posted by 구차니
Linux API/network2019. 7. 3. 13:30

음.. 두개는 연관이 없는 건가? 헷갈림

 

raw socket

sd = socket(PF_INET, SOCK_RAW, IPPROTO_UDP);

[링크 : https://www.tenouk.com/Module43a.html]

[링크 : http://naver.pages.kr/140042345641]

 

#define IPPROTO_TCP 6

#define IPPROTO_UDP 17

[링크 : https://unix.superglobalmegacorp.com/BSD4.4/newsrc/netinet/in.h.html]

 

promiscous mode

s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))

[링크 : https://sangchul.kr/530]

[링크 : https://stackoverflow.com/questions/114804/reading-from-a-promiscuous-network-device]

 

#define ETH_P_ALL 0x0003 /* Every packet (be careful!!!) */

[링크 : https://github.com/spotify/linux/blob/master/include/linux/if_ether.h]

 

 

PF_*, AF_* 차이(없다)

[링크 : http://blog.naver.com/PostView.nhn?blogId=l18400&logNo=60109296392]

 

AF_INET is used, if you want to communicate using Internet protocols: TCP or UDP.

AF_PACKET is used if you want to play with packets at the protocol level, i.e. you are implementing your own protocol. Only processes with effective UID 0 [root] or the capability CAP_NET_RAW may open packet sockets.

[링크 : https://www.quora.com/Whats-the-difference-between-the-AF_PACKET-and-AF_INET-in-python-socket]

'Linux API > network' 카테고리의 다른 글

TCP timeout  (0) 2020.09.29
UDS (Unix Domain Socket)  (0) 2020.09.01
리눅스 UDP 소켓  (0) 2019.05.24
리눅스 TCP 소켓  (0) 2019.05.24
linux udp cpp example  (0) 2019.05.16
Posted by 구차니