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 구차니
Programming/c# & winform2020. 9. 28. 11:13

오.. 신기신기..

어떻게 빌드하지?하다가

아무생각 없이 그냥 해당 프로젝트 디렉토리 들어가니 mono develop 아이콘이 똭!

더블 클릭해서 실행하니 mono develop  가 뜨고 빌드 옵션을 Debug에서 Release로 바꾸고

빌드하니

 

띠용.. PE32 executable 이 뜬다.

~/ar/bin/Release$ file *
ar.exe:        PE32 executable (GUI) Intel 80386 Mono/.Net assembly, for MS Windows
ar.exe.config: XML 1.0 document, UTF-8 Unicode (with BOM) text, with CRLF line terminators
ar.pdb:        Microsoft Rosyln C# debugging symbols version 1.0

 

물론 윈도우에서 프로젝트 파일 자체를 그대로 전송해 왔기 때문에

Deub로 가면 아래와 같이 나오는데 pdb는 메시지가 조금 다른데 exe는 리눅스 상에서 인식하는 포맷이 동일하게 나온다.

~/ar/bin/Debug$ file *
ar.exe:        PE32 executable (GUI) Intel 80386 Mono/.Net assembly, for MS Windows
ar.exe.config: XML 1.0 document, UTF-8 Unicode (with BOM) text, with CRLF line terminators
ar.pdb:        MSVC program database ver 7.00, 512*115 bytes

 

그나저나 4.7의 모든 것 이라고 해놓고

WPF, WWF 그리고 제한된 WCF 그리고 제한된 ASP.NET 비동기 stack을 제외한... (야이!!!)

Everything in .NET 4.7 except WPF, WWF, and with limited WCF and limited ASP.NET async stack.

[링크 : https://www.mono-project.com/docs/about-mono/compatibility/]

 

WWF는 처음 듣네? 검색해보니 레슬링이 왜 나오냐 ㅠㅠ

Windows Workflow Foundation

[링크 : https://docs.microsoft.com/ko-kr/dotnet/framework/windows-workflow-foundation/]

 

그냥 무난하게 winform으로 작성한건 그럼 리눅스에서 빌드하고 실행이 가능한데

GUI자체는 노가다 하거나 visual studio community에서 하는수 밖에 없나?

'Programming > c# & winform' 카테고리의 다른 글

winform socket  (0) 2020.09.29
c# conditional attribute  (0) 2020.09.29
c# 오버라이드, 하이드, 쉐도우  (0) 2020.09.23
c# 상속  (0) 2020.09.23
c#은 main()이 아니다 Main()이다 -_-  (0) 2020.09.23
Posted by 구차니