CPU 쿨러를 들어내고 나서 찍은 사진..
3년만에 이정도 밖에 안쌓인거면 다행인건가?

아무튼, 쿨러 몇개는 거의 고장나서 기름 칠해주고 돌리니
뱅글뱅글~ 졸라 조용한 내 자리!
Posted by 구차니
개소리 왈왈2010. 4. 21. 01:48
1.
선이 있다.
왼쪽과 오른쪽이 생긴다.
아니 갈라진다.


왼쪽이 옳다면 오른쪽이 그르고
오른쪽이 옳다면 왼쪽이 그른것일까?

그렇다면 선을 따라가면 그건 틀린것일까




문득 후배의 넉두리를 듣고 있자니
내 몸 하나 건사하지 못하면서
남에 걱정이나 들어주는 내 신세가 답답하기만 해진다.



2.
어른이 되어간다는 것.
시스템을 안정화 시키면서 평균 출력을 올리되 최대 출력을 낮추는 것.
어쩌면 이것 이상도 이하도 아닌, 딱 이 수준이 아닐까 싶다.




3.

자면서 꾸는것도 꿈이고, 내가 무언가를 갈망하는 것도 꿈이지만
어른이 되어간다는 것과 더불어 부쩍 들어가는 상실감 중에
다중적인 꿈이 포함된게 아닐까 생각된다.

어느샌가부터 꿈을 꾸는지 조차 모르게 되었고
내가 지금 꾸고 있는 꿈이 구체화 되지 않고 있다.




4.
무와 유. 그리고 부유
지금 내 정신상태는 존재냐 사라지냐 그 경계선에서 두둥실 떠있다.
고 표현하는게 옳을지도 모르겠다.

근데.. 1번에서 처럼
정신줄 붙잡고 유를 지키는게 옳은일일까. 아니 제대로 된 일일까
아니면 사라지는게 옳은일일까. 이대로 있는건 어떨까?

'개소리 왈왈' 카테고리의 다른 글

페이스북 가입!  (4) 2010.04.28
비온다.  (8) 2010.04.26
딸기  (8) 2010.04.18
전 지대로 컴맹이빈다 /ㅁ/  (8) 2010.04.14
매정한 네이버  (12) 2010.04.12
Posted by 구차니
Linux2010. 4. 20. 22:43
예전글인 이녀석
2008/12/22 - [Linux] - 심볼릭 링크에 대한 미스테리
왜 심볼릭 링크의 크기는 파일크기와 문자열 길이가 동일할까? 라는 의문이 들었는데,
not null-terminated 라고 함은, inode 쪽에서 filename 변수를 가지고,
실제로 filename 변수에는 \0(=NULL)이 없기 때문이 아닐까 싶다.

i-node에는 파일의 속성이 저장되고,
디렉토리 구조체에 파일의 i-node와 파일의 이름이 저장된다.
# vi /usr/include/bits/dirent.h
struct dirent
  {
#ifndef __USE_FILE_OFFSET64
    __ino_t d_ino;
    __off_t d_off;
#else
    __ino64_t d_ino;
    __off64_t d_off;
#endif
    unsigned short int d_reclen;
    unsigned char d_type;
    char d_name[256];           /* We must not include limits.h! */
  };

# vi /usr/include/bits/stat.h
struct stat
  {
    __dev_t st_dev;                     /* Device.  */
    unsigned short int __pad1;
#ifndef __USE_FILE_OFFSET64
    __ino_t st_ino;                     /* File serial number.  */
#else
    __ino_t __st_ino;                   /* 32bit file serial number.    */
#endif
    __mode_t st_mode;                   /* File mode.  */
    __nlink_t st_nlink;                 /* Link count.  */
    __uid_t st_uid;                     /* User ID of the file's owner. */
    __gid_t st_gid;                     /* Group ID of the file's group.*/
    __dev_t st_rdev;                    /* Device number, if device.  */
    unsigned short int __pad2;
#ifndef __USE_FILE_OFFSET64
    __off_t st_size;                    /* Size of file, in bytes.  */
#else
    __off64_t st_size;                  /* Size of file, in bytes.  */
#endif
    __blksize_t st_blksize;             /* Optimal block size for I/O.  */

#ifndef __USE_FILE_OFFSET64
    __blkcnt_t st_blocks;               /* Number 512-byte blocks allocated. */
#else
    __blkcnt64_t st_blocks;             /* Number 512-byte blocks allocated. */
#endif
#ifdef __USE_MISC
    /* Nanosecond resolution timestamps are stored in a format
       equivalent to 'struct timespec'.  This is the type used
       whenever possible but the Unix namespace rules do not allow the
       identifier 'timespec' to appear in the  header.
       Therefore we have to handle the use of this header in strictly
       standard-compliant sources special.  */
    struct timespec st_atim;            /* Time of last access.  */
    struct timespec st_mtim;            /* Time of last modification.  */
    struct timespec st_ctim;            /* Time of last status change.  */
# define st_atime st_atim.tv_sec        /* Backward compatibility.  */
# define st_mtime st_mtim.tv_sec
# define st_ctime st_ctim.tv_sec
#else
    __time_t st_atime;                  /* Time of last access.  */
    unsigned long int st_atimensec;     /* Nscecs of last access.  */
    __time_t st_mtime;                  /* Time of last modification.  */
    unsigned long int st_mtimensec;     /* Nsecs of last modification.  */
    __time_t st_ctime;                  /* Time of last status change.  */
    unsigned long int st_ctimensec;     /* Nsecs of last status change.  */
#endif
#ifndef __USE_FILE_OFFSET64
    unsigned long int __unused4;
    unsigned long int __unused5;
#else
    __ino64_t st_ino;                   /* File serial number.  */
#endif
  };

다르게 생각해 보자면,
directory table에 파일 이름이 저장되고, (심볼릭 링크)
속성으로 심볼릭 링크가 지정되며,
inode의 filesize는 string이 아닌 data로서 \0(=NULL)이 빠진 순수한 원본 경로만 들어가서
ls 시의 심볼릭 링크 파일의 크기가 예상과 달리 -1 크기로 나오는게 아닐까 싶다.

#include <unistd.h>
ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize);

Return Value
Upon successful completion, readlink() shall return the count of bytes placed in the buffer. Otherwise, it shall return a value of -1, leave the buffer unchanged, and set errno to indicate the error.

[링크 : http://linux.die.net/man/3/readlink]

The readlink function gets the value of the symbolic link filename. The file name that the link points to is copied into buffer. This file name string is not null-terminated; readlink normally returns the number of characters copied. The size argument specifies the maximum number of characters to copy, usually the allocation size of buffer.

[링크 : http://www.gnu.org/s/libc/manual/html_node/Symbolic-Links.html]

APPLICATION USAGE
    Conforming applications should not assume that the returned contents of the symbolic link are null-terminated.

RATIONALE
    Since IEEE Std 1003.1-2001 does not require any association of file times with symbolic links, there is no requirement that file times be updated by readlink(). The type associated with bufsiz is a size_t in order to be consistent with both the ISO C standard and the definition of read(). The behavior specified for readlink() when bufsiz is zero represents historical practice. For this case, the standard developers considered a change whereby readlink() would return the number of non-null bytes contained in the symbolic link with the buffer buf remaining unchanged; however, since the stat structure member st_size value can be used to determine the size of buffer necessary to contain the contents of the symbolic link as returned by readlink(), this proposal was rejected, and the historical practice retained.

[링크 : http://www.opengroup.org/onlinepubs/000095399/functions/readlink.html]

'Linux' 카테고리의 다른 글

ubuntu 9.10 에서 APM + viewvc + cvsgraph 돌리기  (0) 2010.04.28
enscript  (0) 2010.04.28
pwd(getcwd), cd(chdir)  (4) 2010.04.19
wget  (4) 2010.04.10
/dev의 major minor에 대하여  (0) 2010.04.08
Posted by 구차니
프로그램 사용/busybox2010. 4. 20. 20:08
원인은 못찾았지만, 커널 옵션에서 quiet 주어도 나오길래, 최소한 커널 오류는 아닌것으로 판단
busybox에서 찾아보니

./shell/ash.c:4849:     ash_msg_and_raise_error("cannot open %s: %s", fname, errmsg(errno, "no such file"));

한녀석이 걸려 나온다.

특이한건, 이 소스가 있는 부분은 openredirect라는 함수.
음.. 머하는 녀석일려나?

static int
openredirect(union node *redir)
{
    char *fname;
    int f;

    switch (redir->nfile.type) {
    case NFROM:
        fname = redir->nfile.expfname;
        f = open(fname, O_RDONLY);
        if (f < 0)
            goto eopen;
        break;
    case NFROMTO:
        fname = redir->nfile.expfname;
        f = open(fname, O_RDWR|O_CREAT|O_TRUNC, 0666);
        if (f < 0)
            goto ecreate;
        break;
    case NTO:
        /* Take care of noclobber mode. */
        if (Cflag) {
            fname = redir->nfile.expfname;
            f = noclobberopen(fname);
            if (f < 0)
                goto ecreate;
            break;
        }
        /* FALLTHROUGH */
    case NCLOBBER:
        fname = redir->nfile.expfname;
        f = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666);
        if (f < 0)
            goto ecreate;
        break;
    case NAPPEND:
        fname = redir->nfile.expfname;
        f = open(fname, O_WRONLY|O_CREAT|O_APPEND, 0666);
        if (f < 0)
            goto ecreate;
        break;
    default:
#if DEBUG
        abort();
#endif
        /* Fall through to eliminate warning. */
    case NTOFD:
    case NFROMFD:
        f = -1;
        break;
    case NHERE:
    case NXHERE:
        f = openhere(redir);
        break;
    }

    return f;
 ecreate:
    ash_msg_and_raise_error("cannot create %s: %s", fname, errmsg(errno, "nonexistent directory"));
 eopen:
    ash_msg_and_raise_error("cannot open %s: %s", fname, errmsg(errno, "no such file"));
}


2010.04.21 추가
inittab에 ttyAS1을 초기화 하는 부분이 있었는데, 커널에서(?) 사용하지 않도록 해놔서 계속 에러가 난 모양이다.
아무튼, /bin/sh에 ttyAS1을 열도록 해놓았기 때문에, busybox에서 ash이 sh을 대체하고,
그러다 보니 ash에서 에러발생. 머.. 문제 해결 끝!

$ cat target/etc/inittab
# Example Busybox inittab
::sysinit:/etc/init.d/rcS
ttyAS0::askfirst:/bin/sh
ttyAS1::askfirst:/bin/sh
::ctrlaltdel:/sbin/reboot
::shutdown:/sbin/swapoff -a
::shutdown:/bin/umount -a -r
::restart:/sbin/init

'프로그램 사용 > busybox' 카테고리의 다른 글

busybox tftp  (0) 2013.06.18
busybox - setconsole  (0) 2011.10.21
busybox ps는 BSD 스타일?  (0) 2010.01.12
ifup / ifdown 을 통한 static <-> dhcp 변환  (0) 2009.12.29
udhcpd 용 interface 예제  (0) 2009.12.23
Posted by 구차니
iconv_open() 함수는 dest, source 형식으로 인자를 받고
iconv() 함수는 2중 포인터를 사용한다.

#include <iconv.h>

iconv_t iconv_open(const char *tocode, const char *fromcode);
size_t iconv(iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft);

iconv_open(TO, FROM);
이므로 반대로 넣으면 이상하게 나온다. 주의요망!

그리고 iconv() 함수는
문자열 변수들은 2중 포인터로 넘겨주고(왜?)
inbytesleft는 strlen(*inbuf) 의 값을
outbytesleft는 strlen(*outbuf) 의 값을 넣어주면된다.

물론 변환에 따라서, 길이가 가변적으로 달라질수 있기 때문에 주의해야 한다.

만약, 변환중 메모리가 넘치게 되면 EILSEQ 에러가 발생하게 되며, (물론 넘치기 전에 데이터는 빼낼수 있다.)
변수의 포인터가 2중 포인터가 아니면
"__gconv: Assertion `outbuf != ((void *)0) && *outbuf != ((void *)0)' failed."
이런 에러를 만나게 될 것이다.


#include "stdio.h"
#include "string.h"
#include "iconv.h"
#include "errno.h"

#define BUFF_SIZE 64

int main()
{
        iconv_t cd = iconv_open("UNICODE", "UTF-8");
        if (cd == (iconv_t)(-1))
        {
                perror("iconv_open");
                return 0;
        }

        char inBuf[BUFF_SIZE] = "Hello world";
        int inBufSize = sizeof(inBuf);

        char outBuf[BUFF_SIZE];
        int outBufSize = sizeof(outBuf);
        memset(outBuf, 0, outBufSize);

        // convert
        size_t readBytes = strlen(inBuf);
        size_t writeBytes = sizeof(outBuf);
        char* in = inBuf;
        char* out = outBuf;

        printf("readBytes:%d writeBytes:%d\n",readBytes,writeBytes);

        if (iconv(cd, &in, &readBytes, &out, &writeBytes) == -1)
        {
                printf("failed to iconv errno:%d EILSEQ:%d\n", errno, EILSEQ);
        }
        else
        {
                int idx;
                printf("in:%x out:%x\n",in,out);
                printf("readBytes:%d writeBytes:%d\n",readBytes,writeBytes);
                for(idx = 0; idx < BUFF_SIZE; idx++)
                {
                        printf("%03d %c %x\t\t", idx, inBuf[idx], inBuf[idx]);
                        printf("%03d %c %x\n", idx, outBuf[idx], outBuf[idx]);
                }
                outBuf[writeBytes] = '\0';
        }

        iconv_close(cd);
        return 0;
}


2010/04/20 - [Linux] - linux iconv 테스트
2010/04/19 - [Linux] - iconv

Posted by 구차니
iconv 유틸리티를 이용해서 일단 변환 테스트.
-f=UTF-8        (UTF-8 문서를)
-t=UNICODE   (유니코드로 변환)
-o result.txt    (result.txt로 출력)

$ cat test.str
Hello world
$ vi test.str
  1 Hello world

$ iconv -f=UTF8 -t=UNICODE test.str -o result.txt

$ cat result.txt
▒▒Hello world
$ vi result.txt
  1 ÿþH^@e^@l^@l^@o^@ ^@w^@o^@r^@l^@d^@
  2 ^@




Posted by 구차니
언어는 &hl
국가는 &gl 로 변수를 넘겨준다.
(웹상에서 언어를 변경할때는 이렇게 되는데 RSS Feed에는 영향을 미치지 못하는 것으로 보인다.)

http://gdata.youtube.com/feeds/api/standardfeeds/regionID/feedID?v=2

http://gdata.youtube.com/feeds/api/standardfeeds/ko/top_rated
위의 주소는, 한국의 top rated를 받아오는 방법이다.

Country Region ID
Australia AU
Brazil BR
Canada CA
Czech Republic CZ
France FR
Germany DE
Great Britain GB
Holland NL
Hong Kong HK
India IN
Ireland IE
Israel IL
Italy IT
Japan JP
Mexico MX
New Zealand NZ
Poland PL
Russia RU
South Korea KR
Spain ES
Sweden SE
Taiwan TW
United States US

[링크 : http://code.google.com/intl/ko-KR/apis/youtube/2.0/reference.html]

http://gdata.youtube.com/schemas/2007/categories.cat?hl=<LANGUAGE>
위의 내용은, 스키마를 언어별로 받아오는 것이다.
간단하게 카테고리별 문자열을 구글에게서 받아올수 있다.(내부적인 번역이 필요없다!)

Language/Locale hl Parameter Value
Chinese (Traditional) zh-TW
Czech cs-CZ
Dutch nl-NL
English (Great Britain, Ireland, Australia and New Zealand) en-GB
English (United States and Canada)
* default value
en-US
French fr-FR
German de-DE
Italian it-IT
Language/Locale hl Parameter Value
Japanese ja-JP
Korean ko-KR
Polish pl-PL
Portuguese (Brazil) pt-BR
Russian ru-RU
Spanish (Spain) es-ES
Spanish (Mexico) es-MX
Swedish sv-SE

[링크 : http://code.google.com/intl/ko-KR/apis/youtube/2.0/reference.html]

Posted by 구차니
http://gdata.youtube.com/feeds/api/
에서 XML 파일을 받으면 기본적으로

<openSearch:startIndex>1</openSearch:startIndex>
<openSearch:itemsPerPage>25</openSearch:itemsPerPage>

첫번째 페이지, 25개 항목을 받아오도록 되어있다.
즉, 인자를 넘겨주면 다른 값을 볼수도 있다는 의미!

<link rel='previous' type='application/atom+xml'
  href='http://gdata.youtube.com/feeds/api/videos?start-index=1&max-results=25...'/>
<link rel='next' type='application/atom+xml'
  href='http://gdata.youtube.com/feeds/api/videos?start-index=51&max-results=25...'/>

[링크 : http://code.google.com/intl/ko-KR/apis/youtube/2.0/reference.html]


2010.05.07 추가
start-index 는 대소문자 구분하며, 1 부터 시작한다.

'프로그램 사용 > 유튜브(youtube)' 카테고리의 다른 글

youtube api 변동으로 인한 content 태그 변경  (0) 2010.05.13
youtube locale 관련  (0) 2010.04.20
youtube html5  (2) 2010.04.17
Percent encoding = URL Encoding  (0) 2010.04.16
유튜브 fmt 와 t 값  (0) 2010.04.15
Posted by 구차니
Linux2010. 4. 19. 17:13
리눅스에서 cd는 디렉토리를 변경하고,
pwd는 현재 작업 디렉토리를 보여준다.

그걸 api 수준에서 보자면
cd는 chdir() 이고
pwd는 getcwd() 이다.

long getcwd(char *buf, unsigned long size);

#include <unistd.h>
int chdir(const char *path);
int fchdir(int fd);

[링크 : http://linux.die.net/man/3/getcwd]
[링크 : http://linux.die.net/man/3/chdir]


2010.04.20 추가

코드샘플
#include "unistd.h"

void main()
{
	int ret;
	char buff[256];
	
	getcwd(buff, 255);
	printf("%s\n",buff);
	
	ret = chdir("/etc");

	getcwd(buff, 255);
	printf("%s\n",buff);	
}

Posted by 구차니
iconv는 utf 나 iso8859 등, 여러가지 방법으로
문자열 코딩을 변환해주는 역활을 하는 함수/유틸리티이다.

$ man -k iconv
iconv                (1)  - Convert encoding of given files from one encoding to another
iconv                (1p)  - codeset conversion
iconv                (3)  - perform character set conversion
iconv                (3p)  - codeset conversion function
iconv.h [iconv]      (0p)  - codeset conversion facility
iconv_close          (3)  - deallocate descriptor for character set conversion
iconv_close          (3p)  - codeset conversion deallocation function
iconv_open           (3)  - allocate descriptor for character set conversion
iconv_open           (3p)  - codeset conversion allocation function
아무튼, iconv는 함수(3/3p) 이자 유틸리티(1) 인데
함수의 경우 iconv_open() - iconv() - iconv_close() 를 이용하여 사용한다.

#include <iconv.h>
iconv_t iconv_open(const char *tocode, const char *fromcode);

tocode나 fromcode에 들어갈 내용은
명령어로 확인이 가능하다.

$ ldd /usr/bin/iconv
        linux-gate.so.1 =>  (0x005e5000)
        libc.so.6 => /lib/libc.so.6 (0x47ae8000)
        /lib/ld-linux.so.2 (0x47119000)
ldd로 확인해보니, libc만 있으면 실질적으로 구동이 가능한 함수로 보인다.

테스트가 필요한 코드
[링크 : http://kldp.org/node/77391]
[링크 : http://www.korone.net/bbs/board.php?bo_table=etc_misc&wr_id=160&page=2]
Posted by 구차니