[C/C++] Variadic function의 default argument promotion

C/C++에서 함수에 가변 인자를 사용할 때, 그 parameter의 타입을 컴파일러가 알 수 없기 때문에, 컴파일러가 좀 쉽게 알 수 있도록, int보다 작은 타입은 int 혹은 unsigned int로, float은 double로 promotion이 일어난다고 한다.

이를 무시하고, va_start(), va_args() 매크로를 사용하면, undefined behavior이다.

[QuickBuild] RESTful API로 빌드 요청

QuickBuild를 이용할 때, 굳이 사이트에 접속해서 빌드를 돌리지 않아도 RESTful API를 이용하면 빌드를 걸 수 있다.

http://wiki.pmease.com/display/QB61/Interact+with+Build+Requests#InteractwithBuildRequests-requestnewbuild 에 해당 내용이 정리되어 있다.

Basic authentication 시에 curl을 이용해서 요청하는 방법은 다음과 같다.

$ curl -X POST -u dasomoli:password -d@request.xml http://<Server>:8810/rest/build_requests

위의 예제에서 사용한 request.xml 은 다음의 형식을 가진다. <varlables> 안에 채울 내용은 해당 configuration에서 실행한 빌드의 variables(http://<Server>:8810/build/<Build id>/variables) 페이지에서 확인 가능하다.

<com.pmease.quickbuild.BuildRequest>
  <!-- This element tells QuickBuild in what configuration to trigger build. -->
  <configurationId>10</configurationId>

  <!-- This element tells whether or not to respect build condition of the configuration. 
       If this is set to true, and if the build condition evaluates to false, build will 
       not be triggered. -->
  <respectBuildCondition>false</respectBuildCondition>

  <!-- This element is optional and is used to specify variables for build triggering. If 
       specified, it will override the variable with the same name defined in configuration
       basic setting. -->
  <variables>
    <entry>
      <string>var_name1</string>
      <string>var_value1</string>
    </entry>
    <entry>
      <string>var_name2</string>
      <string>var_value2</string>
    </entry>
  </variables>

  <!-- This element is optional and is used to tell QuickBuild to request a build promotion. -->
  <promotionSource>

    <!-- This element is optional and is used to tell QuickBuild that the source build resides on another 
         QuickBuild server. -->
    <server>
      <url>http://another-qb-server:8810</url>
      <userName>admin</userName>
      <password>admin</password>
    </server>

    <!-- Identifier of the source build to promote from -->
    <buildId>697</buildId>

    <!-- This element is optional and used to specify files to promote -->
    <deliveries>
      <com.pmease.quickbuild.FileDelivery>
        <srcPath>artifacts/dir1</srcPath>
        <filePatterns>**/*.jar</filePatterns>
      </com.pmease.quickbuild.FileDelivery>
      <com.pmease.quickbuild.FileDelivery>
        <srcPath>artifacts/dir2</srcPath>
        <filePatterns>**/*.war</filePatterns>
      </com.pmease.quickbuild.FileDelivery>
    </deliveries>
  </promotionSource>

</com.pmease.quickbuild.BuildRequest>

Sample XML의 comment에서 확인할 수 있듯이 <promotionSource>내부는 생략 가능하다.

[RaspberryPi] USB Port control

24시간 내내 돌리면 라즈베리 파이가 너무 뜨거울 것 같아서 USB 선풍기를 포트에 연결하고, 이걸 껐다 켰다 하려고 시도했다. 결론적으론 다른 USB 기기를 쓰지 않는다면, 전체 USB 포트를 껐다 켜는 방식으로 가능하다. 다른 USB 기기를 사용한다면, 실패. 아직 디바이스 드라이버에 커널 컴파일까진 시도하고 싶지 않다.

https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=93463 쓰레드를 참고하면, hub-ctrl을 이용하면, 전체 포트 혹은 개별 포트를 껐다 켰다 하는 것을 할 수 있다.  그러나 개별 포트를 끄는 게, 실제 VBUS 전원까지 내리는 건 아니고, 그냥 못쓰게 할 뿐이다. 그래서, 전체 포트를 끄지 않는 한, 개별 포트를 꺼도 해당 포트 VBUS는 살아있기 때문에 USB 선풍기는 계속 돈다-_-;;

다음은 usb-ctrl의 설치 및 사용 방법이다.

라즈베리 파이에서 다음을 설치한다.

# apt-get install libusb-dev

다음으로 바이너리를 만든다.

# apt-get install git gcc
# git clone https://github.com/codazoda/hub-ctrl.c
# gcc -o hub-ctrl hub-ctrl.c -lusb

만든 바이너리를 적당한 곳(예를 들면, /usr/sbin/)에 설치한다.

# cp hub-ctrl /usb/sbin/

나의 경우 한 시간에 한번 정도, 50초 정도 돌게 하고 싶었다. /etc/cron.hourly 아래에 다음과 같은 스크립트를 만들어 실행 권한을 준다.

# vi /etc/cron.hourly/coolingusbfan
#!/bin/sh
hub-ctrl -h 0 -P 2 -p 1; sleep 50; sudo hub-ctrl -h 0 -P 2 -p 0

참고로, 다음 그림과 같이 포트 번호를 붙인다면,

라즈베리 파이 3 Model B의 경우, 다음과 같다고 한다.

Hub:Port — Controlled port(s)
0:1 — Controls the Ethernet port
0:2 — Controls all four USB ports (not the Ethernet)
0:3 — Controls USB Port 4
0:4 — Controls USB Port 2
0:5 — Controls USB Port 3

NAS를 위해, 외장 하드를 붙일 거라 이제 더는 위 스크립트를 사용하지 못한다.

‘진짜배기 코드 평가자라면 하지 말아야 할 네 가지’를 읽고

개인의 경우는 대체적으로 설득 가능하다. 그러나, 모든 팀원이 그래서 모두를 설득해야 한다면, 팀 혹은 회사 차원의 문제다. 이런 경우, 개인을 설득하려 해도, “다들 그래요”, “그게 여기서 되겠어요?”, “그거 한다고 안바뀌어요”, “당신 때문에 내 코드가 못들어가고 있어요. 오늘 릴리즈인데, 당신이 책임질거요?” 따위의 말이나 듣는다. ‘협업 안되는 사람’이 되고.

내가 아는 어떤 회사가 그랬다. 요즘은 좀 바꾸려고 하는 것 같던데, 이런 사람들이 위에서 때리면, 제일 먼저 자기는 안그런다 하더라.

만약 당신이 동료를 향해 신경쓰이는 기분이 든다면 회사 혹은 팀의 경영 측면에서 문제가 있는 겁니다.

(번역) 진짜배기 코드 평가자라면 하지 말아야 할 네 가지

[Eclipse] Source code Navigation 단축키

Eclipse는 내부적으로 Indexer가 돌아서 이를 이용해 찾고 싶은 File, Funtion decalaration/definition, symbol 등을 찾을 수 있다. 내가 자주 쓰는 단축키는 다음과 같다.

  • F3: Funtion declaratiin/definition. 함수 선언이나, 함수 정의로 이동하고 싶을 때 사용한다.
  • Alt + ‘<-‘: 이전 코드. 이전에 보던 부분으로 돌아갈 때 사용한다.
  • Ctrl + Shift + ‘R’: File name 찾아서 열기. 파일 이름을 알 때, 혹은 앞 몇글자만 기억날 때, 찾아서 연다.
  • Ctrl + Shift + ‘G’: Workspace에서 Reference 찾기. 함수 호출되는 부분을 찾고 싶을 때 사용한다.
  • Ctrl + ‘H’: Search. 주로 File Search를 이용한다. Scope을 셋팅해서 쓰는 것도 좋다.
  • Ctrl + Alt + ‘G’: Workspace에서 Text 찾기. Ctrl + ‘H’ 대신 사용하기도 한다.
  • Ctrl + ‘O’: Quick Outline. 주로 함수를 찾아 이동할 때 사용한다.

curl 사용법

curl 잘쓰면 엄청 편하다.
* HTTP 전송 과정에 대한 상세 정보. curl이 하는 모든 일을 debugdump.txt에 저장한다.
curl –trace-ascii debugdump.txt http://blog.dasomoli.org/
* 일반적인 http 요청(GET method)
curl http://blog.dasomoli.org/
* HTTP authentication
curl -u <id>:<password> http://blog.dasomoli.org/
* POST method 요청
curl -X POST -d”<data>” http://blog.dasomoli.org:80/post/
다음과 같은 form이 있다면,
<form method=”POST” action=”dasomoli.cgi”>
<input type=text name=”id”>
<input type=submit name=press value=” OK “>
</form>
다음과 같이 전송 가능((hidden type도 그냥 쓰면 됨)
curl –data “id=dasomoli&press=%20OK%20”  http://blog.dasomoli.org/dasomoli.cgi
–data-urlencode를 쓰면 %20같이 쓰지 않고, 아래처럼도 가능하다고 한다.
curl –data-urlencode “name=JeongSeok Yang” http://blog.dasomoli.org/dasomoli.cgi
* POST로 파일 보내기
curl -X POST -d@<filename> http://blog.dasomoli.org/post/
* PUT method
curl –upload-file uploadfile http://blog.dasomoli.org/receiveput.cgi
* JSON 전송
curl -X POST http://blog.dasomoli.org/json/ -d@dasomoli.json -H “Content-Type: application/json”
* 쿠키 쓰기
curl -b cookie.txt -c cookie.txt http://blog.dasomoli.org/